HDU2079选课时间(母函数)

母函数的简单应用http://acm.hdu.edu.cn/showproblem.php?pid=2079

介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数)

 1 #include<stdio.h>
 2 
 3 
 4 
 5 int main()
 6 {
 7     int T;
 8     while(~scanf("%d", &T))while(T--)
 9     {
10         int c1[41]={0},c2[41]={0};
11         int num,val;
12         int i,n,k;
13         scanf("%d%d", &n, &k);
14         for(i = 1; i<=k;i++)
15         {
16             scanf("%d%d",&val, &num);
17             if(i ==1)
18             {
19                 for(int j = 0; j<=num && j*val<=n ;j++)
20                 {
21                     c1[j*val] = 1;
22                     c2[j*val] = 0;
23                 }
24             }
25             else
26             {
27                 for(int j = 0;j <= n;j ++ )
28                 {
29                     for(int t = 0;t*val +j <=n && t<=num; t++)
30                     {
31                         c2[j+t*val] += c1[j];
32                     }
33                 }
34                 for(j =0;j<=n;j++)
35                 {
36                     c1[j]=c2[j];
37                     c2[j]=0;
38                 }
39             }
40         }
41         printf("%d\n", c1[n]);
42     }
43     return 0;
44 }

 

转载于:https://www.cnblogs.com/gj-Acit/p/3201739.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值