UVa 10105 Polynomial Coefficients(排列组合)

题意:

x1n1x2n2...xknk的系数

思路:

排列组合知识。

#include <cstdio>
#include <cstdlib>
#include <cstring>

const int MAXN = 20;
int c[MAXN][MAXN];

void init()
{
    for (int i = 0; i < MAXN; ++i)
        c[i][0] = c[i][i] = 1;

    for (int i = 2; i < MAXN; ++i)
        for (int j = 1; j < i; ++j)
            c[i][j] = c[i-1][j] + c[i-1][j-1];
}

int main()
{
    int n, k;
    init();
    while (scanf("%d %d", &n, &k) != EOF)
    {
        int a[MAXN];
        for (int i = 0; i < k; ++i)
            scanf("%d", &a[i]);

        int ans = 1;
        for (int i = 0; i < k; ++i)
            ans *= c[n][a[i]], n -= a[i];

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

 

posted @ 2012-12-09 21:39  kedebug  阅读(343)  评论(0编辑  收藏  举报