原題鏈接:HDU’s ACM 1521 排列組合
分析:這是能夠體現指數型母函數的一道題目,因爲有n種物品,且每種物品的數目都可能不唯一,數量記爲a1,a2,a3…;則在排列時,抽取數目爲k時,因爲被視爲一種情形,故要在係數上除以k!;綜上,可以如此處理後,再乘上m!.
AC Code:
<span style="font-family:Microsoft YaHei;font-size:14px;">#include <stdio.h>
double f[] = {1,1,2,6,24,120,720,5040,40320,362880,3628800};
int main()
{
int n, m;
while(scanf("%d%d", &n, &m) != EOF) {
double num[11] = {0}, c1[11] = {0}, c2[11] = {0};
int i, j, k;
for(i=0;i<n;++i)
scanf("%lf", &num[i]);
for(i=0;i<=num[0];++i)
c1[i] = 1.0/f[i];
for(i=1;i<n;++i){
for(j=0;j<=m;++j)
for(k=0;k<=num[i] && (k+j)<=m;k+=1)
c2[k+j] += (c1[j]/f[k]);
for(j=0;j<=m;++j){
c1[j] = c2[j];
c2[j] = 0.0;
}
}
double s = 1.0*c1[m]*f[m];
printf("%.0lf\n", s);
}
return 0;
}</span>