博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU3602 2012【dp】
阅读量:4625 次
发布时间:2019-06-09

本文共 3675 字,大约阅读时间需要 12 分钟。

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 
2 #include
3 #include
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

你可能感兴趣的文章
解惑好文:移动端H5页面高清多屏适配方案(2)
查看>>
理解MySQL——索引与优化
查看>>
Java-Runoob:Java 方法
查看>>
杂项:院校
查看>>
Luogu P4551 最长异或路径 01trie
查看>>
通过代码注册COM、DLL组件
查看>>
appium重新封装后,取一组元素之后显示不是列表类型的乌龙(copy有风险,paste需谨慎)...
查看>>
json_encode 中文处理
查看>>
jquery局部区域打印功能实现
查看>>
Centos7 中使用Supervisor守护进程
查看>>
第五周作业
查看>>
awk中关于BEGIN,END的使用问题
查看>>
[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法
查看>>
禁用root登录以及使用sudo分配权限
查看>>
mysql-The program could not be launched,Error Number 2解决办法
查看>>
字节缓冲流 BufferedOutputStream BufferedInputStream
查看>>
身份证正则表达式
查看>>
JS代码放在head和body中的区别分析
查看>>
C++string,char* 字符数组,int类型之间的转换
查看>>
sql 条件处理
查看>>