hdu 1521 排列组合 指数型母函数

 

/*
* hdu1521.c
*
* Created on: 2011-8-31
* Author: 王竹
*/

#include<stdio.h>
#include<string.h>
#define nmax 15
int num[nmax];
double res[nmax], fac[nmax], temp[nmax];
void init(int n) {
int i;
fac[0] = 1;
for (i = 1; i <= n; i++) {
fac[i] = fac[i - 1] * i;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int i, j, k, n, m;
while (scanf("%d %d", &n, &m) != EOF) {
init(n);
for (i = 0; i < n; i++) {
scanf("%d", num + i);
}
memset(res, 0.0, sizeof(res));
memset(temp, 0.0, sizeof(res));
for (i = 0; i <= num[0]; i++) {
res[i] = 1.0 / fac[i];
}
for (i = 1; i < n; i++) {
for (j = 0; j <= n; j++) {
for (k = 0; (k <= num[i]) && (k + j <= n); k++) {
temp[j + k] += res[j] / fac[k];
}
}
for (j = 0; j <= n; j++) {
res[j] = temp[j], temp[j] = 0;
}
}
printf("%.0lf\n", res[m] * fac[m]);
}
return 0;
}

你可能感兴趣的:(HDU)