hdu_2110_Crisis of HDU(母函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2110
题意:给你N个价值和数目,求方案数,很裸的母函数。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 int c1[4000],c2[4000],all,pi[110],mi[110],su,i,j,k; 3 int mu(int sum){ 4 for(i=0;i<=sum;i++)c1[i]=0,c2[i]=0; 5 for(i=0;i<=mi[1];i++)c1[pi[1]*i]=1; 6 for(i=2;i<=all;i++){ 7 for(j=0;j<=mi[i];j++) 8 for(k=0;pi[i]*j+k<=sum;k++)c2[pi[i]*j+k]+=c1[k]%10000; 9 for(j=0;j<=sum;j++)c1[j]=c2[j]%10000,c2[j]=0; 10 } 11 return c1[sum]; 12 } 13 int main(){ 14 while(~scanf("%d",&all),all){ 15 for(i=1,su=0;i<=all;i++)scanf("%d%d",&pi[i],&mi[i]),su+=pi[i]*mi[i]; 16 if(su%3)puts("sorry"); 17 else printf("%d\n",mu(su/3)); 18 } 19 return 0; 20 }