大家好,又见面了,我是全栈君。
http://acm.hdu.edu.cn/showproblem.php?
One day, zhx takes part in an contest. He found the contest very easy for him.
There are
n
ith
ti
vi
As he is too powerful, the administrator is watching him. If he finishes the
ith
li
zhx doesn’t really want to solve all these boring problems. He only wants to get no less than
w
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.
50
EOF
For each test, there are two integers
n
w
1≤n≤30
0≤w≤109
Then come n lines which contain three integers
ti,vi,li
1≤ti,li≤105,1≤vi≤109
1 3 1 4 7 3 6 4 1 8 6 8 10 1 5 2 2 7 10 4 1 10 2 3
7 8 zhx is naive!
/** hdu5188 有限制条件的01背包问题 题目大意:有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,并且一道题不能分开几次做(一旦開始做,必须在ti时间内把它做完) 问得到w分的最小用时是多少 解题思路:非常像01背包的基本题,可是有一个li分钟前不能AC的限制,因此第i道题必须在最早第(li-ti)时刻做,我们依照l-t递增排序,然后依照经典解法来做 即可了 */ #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; struct note { int t,v,l; bool operator <(const note &other)const { return l-t<other.l-other.t; } }node[35]; int n,m; int dp[3000005]; int main() { while(~scanf("%d%d",&n,&m)) { int sum=0,ans=0,up=0; for(int i=0;i<n;i++) { scanf("%d%d%d",&node[i].t,&node[i].v,&node[i].l); sum+=node[i].v; ans+=node[i].t; up=max(up,node[i].l); } if(m>sum) { printf("zhx is naive!\n"); continue; } sort(node,node+n); up=max(up,ans); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=up;j>=node[i].l;j--) { if(j>=node[i].t) { dp[j]=max(dp[j],dp[j-node[i].t]+node[i].v); } } } int flag=0; for(int i=0;i<=up;i++) { if(dp[i]>=m) { printf("%d\n",i); flag=1; break; } } if(flag==0) { printf("zhx is naive!\n"); } } return 0; }
One day, zhx takes part in an contest. He found the contest very easy for him.
There are
n
ith
ti
vi
As he is too powerful, the administrator is watching him. If he finishes the
ith
li
zhx doesn’t really want to solve all these boring problems. He only wants to get no less than
w
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.
50
EOF
For each test, there are two integers
n
w
1≤n≤30
0≤w≤109
Then come n lines which contain three integers
ti,vi,li
1≤ti,li≤105,1≤vi≤109
1 3 1 4 7 3 6 4 1 8 6 8 10 1 5 2 2 7 10 4 1 10 2 3
7 8 zhx is naive!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116013.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...