UVA 10105 Polynomial Coefficients

组合数打表。

(x1+x2+...+xk)^n中的任意一项为C(n,n1)*x1^n1*C(n-n1,n2)*x^n2*C(n-n1-n2,n3)*x^n3*......

#include <iostream>
#include<stdio.h>
#include<cstring>
typedef long long ll;
using namespace std;

ll c[15][15];
void make_table()
{
    memset(c,0,sizeof c);
    c[1][0] = c[1][1] = 1;
    for(int i = 0;i < 13;i++) c[i][0] = 1;
    for(int i = 2;i < 13;i++)
        for(int j = 0;j <= i;j++)
            c[i][j] = c[i-1][j-1]+c[i-1][j];
}

int main()
{
    make_table();
    int n,k,a;
    ll ans;
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        ans = 1;
        for(int i = 0 ;i < k;i++)
        {
            scanf("%d",&a);
            ans*=c[n][a];
            n-=a;

        }
        printf("%lld\n",ans);
    }
    return 0;
}



你可能感兴趣的:(UVA 10105 Polynomial Coefficients)