uva10105-多项式系数

题意

  求(x1 + x2 + x3 +...+xk)n 特定一项的系数。。。

 

代码

#include<stdio.h>
typedef long long ll;
ll C(int n, int k)
{
    ll ans = 1;
    int temp = 0;
    while(temp != k) { ans *= n - temp; temp++; }
    for(int i=1; i<=k; i++) ans /= i;
    return ans;
}
int main()
{
    int ex, m;
    while(scanf("%d%d", &ex, &m) == 2) {
        int array[15];
        for(int i=0; i<m; i++) scanf("%d", &array[i]);
        ll res = 1; int now = ex;
        for(int i=0; i<m; i++) if(array[i]) {
            res *= C(now, array[i]);
            now -= array[i];
        }
        printf("%lld\n", res);
    }
    return 0;
}

 

posted @ 2016-09-15 12:45  啊嘞  阅读(162)  评论(0编辑  收藏  举报