题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2110
题意:给你N个价值和数目,求方案数,很裸的母函数。
#include<cstdio> int c1[4000],c2[4000],all,pi[110],mi[110],su,i,j,k; int mu(int sum){ for(i=0;i<=sum;i++)c1[i]=0,c2[i]=0; for(i=0;i<=mi[1];i++)c1[pi[1]*i]=1; for(i=2;i<=all;i++){ for(j=0;j<=mi[i];j++) for(k=0;pi[i]*j+k<=sum;k++)c2[pi[i]*j+k]+=c1[k]%10000; for(j=0;j<=sum;j++)c1[j]=c2[j]%10000,c2[j]=0; } return c1[sum]; } int main(){ while(~scanf("%d",&all),all){ for(i=1,su=0;i<=all;i++)scanf("%d%d",&pi[i],&mi[i]),su+=pi[i]*mi[i]; if(su%3)puts("sorry"); else printf("%d\n",mu(su/3)); } return 0; }