HDU3602 2012【dp】

2012

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 647    Accepted Submission(s): 246


Problem Description
As we know,2012 is coming,and the presidents of many countries have planned to board the airships.We also know that every president i will bring a[i] bodyguards to make sure his safe,and he will pay b[i] billion dollars to U.N. We also know that some countries are more powerful than others,so if we have chose some countries to board the ship,we must  make the powerful countries board first,and make sure that the bodyguards stay the same ship with his president.
Now,U.N has m ships. And every ship can only contain k people.So cannot hold all the people,but the U.N want to make more mongey .Make the most money for the U.N,then the U.N will give Lazy Yangyang a chance to survive when 2012 is coming.
Lazy Yangyang want to be safe so that he can inherit the job of ACM for the new world.To make the dream come true,the acmers of the world are solving the problem for Lady YY,and you are one of them………
 

 

Input
In the first line there is an integer T, indicates the number of test cases. (T <= 10)
In each case, the first line contains three integers n,m and k. (0 <m<=n <=100,0<k<100000)
Then n line,every line has two integers a[i]、b[i], (0<=a[i]<100000,0<=b[i]<100)representing the bodyguards and dollars, ordered by their power,The first country is the most powerful country.
 

 

Output
Most money that U.N can get.
 

 

Sample Input
1 4 2 400 60 1 180 1 180 1 260 1
 

 

Sample Output
3
Hint
You can choose country 1 3 4,make the 1 3 at ship 1,and make country 4 at ship 2;but you cannot make 1 4 at ship 1, and country 2 3 at ship 2, because 2 is more powerful than country 4, so 2 should sit behind country 1!
 

 

Author
alpc72
 

 

Source
大意:
有n个总统每个总统身边有a[i]个保镖  要上m个飞船 每个飞船能装k个人
选一些总统上船  优先级高的在前边   必须比优先级低先上船
总统必须带所有的保镖都上船  需要支付b[i]的费用
问费用的最大值是多少
 
分析:
dp[i][j]代表前i个人收益为j时最少的乘坐人数
那么dp[i][j + b[i]] = min(dp[i][j + b[i]], 上来a[i]个人的最终乘坐人数)
 
代码:
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 const int maxn = 105;
 7 const int maxm = 10005;
 8 int a[maxn], b[maxn];
 9 int dp[maxn][maxm];
10 
11 int main() {
12     int t;
13     int n, m, k;
14     scanf("%d",&t);
15     while(t--) {
16         scanf("%d %d %d",&n, &m, &k);
17         int Max = 0;
18         int INF = m * k;
19         for(int i = 1; i <= n; i++) {
20             scanf("%d %d",&a[i], &b[i]);
21             a[i]++;
22             Max += b[i];
23         }
24         memset(dp, 0x3f, sizeof(dp));
25         dp[0][0] = 0;
26         for(int i = 1; i <= n; i++) {
27             if(a[i] > k) continue;
28             for(int j = 0;  j <= Max; j++) {
29                 dp[i][j] = min(dp[i][j], dp[i - 1][j]);
30                 if(dp[i - 1][j] <= INF) {
31                     int pnum = dp[i - 1][j];
32                     int anum = a[i];
33                     int ans = 0;
34                     if(pnum % k == 0 || (k - (pnum % k) ) >= anum) {
35                         ans = pnum + anum;
36                     } else {
37                         ans = (pnum / k + 1) * k + anum;
38                     }
39                     if(ans <= m * k) {
40                         dp[i][j + b[i]] = min(dp[i][j + b[i]], ans);
41                     }
42                 } 
43             }
44         }
45         int ans = 0;
46         for(int j = Max; j >= 0; j--) {
47             if(dp[n][j] <= INF) {
48                 ans = j;
49                 break;
50             }
51         }
52         printf("%d\n",ans);
53     }
54     return 0;
55 }
56 
57 
58         
View Code

 

转载于:https://www.cnblogs.com/zhanzhao/p/4125895.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值