码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-19 22:53:30      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

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 选课时间(题目已修改,注意读题)

标签:style   blog   http   color   io   os   ar   for   sp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!