HDU5188:zhx and contest(类01背包)
来源:互联网 发布:nginx alias用法 编辑:程序博客网 时间:2024/05/21 11:19
zhx and contest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 828 Accepted Submission(s): 316
Problem Description
As one of the most powerful brushes in the world, zhx usually takes part in all kinds of contests.
One day, zhx takes part in an contest. He found the contest very easy for him.
There aren problems in the contest. He knows that he can solve the ith problem in ti units of time and he can get vi points.
As he is too powerful, the administrator is watching him. If he finishes theith problem before time li , he will be considered to cheat.
zhx doesn't really want to solve all these boring problems. He only wants to get no less thanw points. You are supposed to tell him the minimal time he needs to spend while not being considered to cheat, or he is not able to get enough points.
Note that zhx can solve only one problem at the same time. And if he starts, he would keep working on it until it is solved. And then he submits his code in no time.
One day, zhx takes part in an contest. He found the contest very easy for him.
There are
As he is too powerful, the administrator is watching him. If he finishes the
zhx doesn't really want to solve all these boring problems. He only wants to get no less than
Note that zhx can solve only one problem at the same time. And if he starts, he would keep working on it until it is solved. And then he submits his code in no time.
Input
Multiply test cases(less than 50 ). Seek EOF as the end of the file.
For each test, there are two integersn and w separated by a space. (1≤n≤30 , 0≤w≤109 )
Then come n lines which contain three integersti,vi,li . (1≤ti,li≤105,1≤vi≤109 )
For each test, there are two integers
Then come n lines which contain three integers
Output
For each test case, output a single line indicating the answer. If zhx is able to get enough points, output the minimal time it takes. Otherwise, output a single line saying "zhx is naive!" (Do not output quotation marks).
Sample Input
1 31 4 73 64 1 86 8 101 5 22 710 4 110 2 3
Sample Output
78zhx is naive!
Source
BestCoder Round #33
题意:略。
HINT:第一组数据,第6s时开始做,第7s完成。第二组数据,第1s时做第3题,第4s时做第1题,第8s时完成。
思路·:由于限制了做题时间,需要排一下序,将先做的题放到前面再用01背包解法。
# include <stdio.h># include <string.h># include <algorithm># define MAXN 100000using namespace std;int dp[MAXN*30+1];struct node{ int t, v, l;}a[31];int cmp(node a, node b) {return a.l-a.t < b.l-b.t;}int main(){ int n, w, totalv, totalt, maxl, max_v; while(~scanf("%d%d",&n,&w)) { totalt = totalv = maxl = 0; for(int i=0; i<n; ++i) { scanf("%d%d%d",&a[i].t, &a[i].v, &a[i].l); totalt += a[i].t; totalv += a[i].v; maxl = max(maxl, a[i].l); } if(totalv < w) { puts("zhx is naive!"); continue; } max_v = max(totalt, maxl); sort(a, a+n, cmp); memset(dp, 0, sizeof(dp)); for(int i=0; i<n; ++i) for(int j=max_v; j>=a[i].l && j>=a[i].t; --j) dp[j] = max(dp[j], dp[j-a[i].t]+a[i].v); for(int i=0;;++i) if(dp[i] >= w) { printf("%d\n",i); break; } } return 0;}
0 0
- HDU5188:zhx and contest(类01背包)
- 【01背包+限制条件】HDU5188-zhx and contest【BestCoder Round #33】
- hdu5188 zhx and contest (DP+map)
- HDU 5188 zhx and contest(有限制01背包)
- HDOJ 题目5188 zhx and contest(01背包,限制)
- hdoj zhx and contest 5188 (01背包)
- HDU-5188-zhx and contest【01背包】
- HDOJ 5188 zhx and contest 贪心+01背包
- HUD 5188(zhx and contest)有条件01背包
- zhx and contest (HDU_5188) 01背包+条件限制
- HDU 5188 zhx and contest 01背包的变形
- HDU 5188 · zhx and contest【01背包】【约束条件】
- HDU 5188 zhx and contest(带限制条件的 01背包)
- hdu 5188 zhx and contest(有限制的01背包问题)
- HDU 5188 && Bestcoder #33 C题. zhx and contest (01背包)
- HDU5188(有限制的01背包)
- hdu5188(01背包变形)
- hdu5188限制01背包
- Hadoop IO流基本操作
- 【PAT】1049. 数列的片段和
- 《算法竞赛入门经典》第三章思考题
- [蓝牙]蓝牙的初步简介与应用 及其技术要点--更新中
- 目录及文件删除
- HDU5188:zhx and contest(类01背包)
- Android SDK Sample(一) CardReader
- 10. Regular Expression Matching
- 13. Roman to Integer
- 进程状态的转换
- 22. Generate Parentheses
- qt 学习笔记6 360 Labe
- 在SSM中使用shiro实现登录验证(附密码加密)
- 23. Merge k Sorted Lists