首页 > 其他 > 详细

hdu 2079 选课时间(题目已修改,注意读题)

时间:2014-10-19 22:51:38      阅读:374      评论:0      收藏:0      [点我收藏+]

http://acm.hdu.edu.cn/showproblem.php?pid=2079

背包

bubuko.com,布布扣
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 3000
 5 using namespace std;
 6 
 7 int dp[maxn];
 8 int a,b;
 9 int t,n,k;
10 
11 int main()
12 {
13     scanf("%d",&t);
14     while(t--)
15     {
16         scanf("%d%d",&n,&k);
17         memset(dp,0,sizeof(dp));
18         dp[0]=1;
19         for(int i=1; i<=k; i++)
20         {
21             scanf("%d%d",&a,&b);
22             for(int j=n; j>=a; j--)
23             {
24                 for(int x=1; x<=b; x++)
25                 {
26                     if(j-x*a>=0)
27                     {
28                         dp[j]+=dp[j-x*a];
29                     }
30                 }
31             }
32         }
33         printf("%d\n",dp[n]);
34     }
35     return 0;
36 }
View Code

 

hdu 2079 选课时间(题目已修改,注意读题)

原文:http://www.cnblogs.com/fanminghui/p/4035636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!