母函数的简单应用http://acm.hdu.edu.cn/showproblem.php?pid=2079
介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数)
#include<stdio.h> int main()
{
int T;
while(~scanf("%d", &T))while(T--)
{
int c1[]={},c2[]={};
int num,val;
int i,n,k;
scanf("%d%d", &n, &k);
for(i = ; i<=k;i++)
{
scanf("%d%d",&val, &num);
if(i ==)
{
for(int j = ; j<=num && j*val<=n ;j++)
{
c1[j*val] = ;
c2[j*val] = ;
}
}
else
{
for(int j = ;j <= n;j ++ )
{
for(int t = ;t*val +j <=n && t<=num; t++)
{
c2[j+t*val] += c1[j];
}
}
for(j =;j<=n;j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
}
printf("%d\n", c1[n]);
}
return ;
}