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; }
-------------------------------------------------------
kedebug
Department of Computer Science and Engineering,
Shanghai Jiao Tong University
E-mail: kedebug0@gmail.com
GitHub: http://github.com/kedebug
-------------------------------------------------------