设为首页 加入收藏

TOP

hdu5188 加限制的01背包问题(一)
2015-07-24 05:02:04 来源: 作者: 【 】 浏览:12
Tags:hdu5188 限制 背包 问题

?

?

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 are n 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 the ith 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 than w 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.
Input Multiply test cases(less than 50 ). Seek EOF as the end of the file.
For each test, there are two integers n and w separated by a space. ( 1≤n≤30 , 0≤w≤109 )
Then come n lines which contain three integers ti,vi,li . ( 1≤ti,li≤105,1≤vi≤109 )
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 3
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3

Sample Output
7
8
zhx is naive!
/**
hdu5188 有限制条件的01背包问题
题目大意:有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,而且一道题不能分开几次做(一旦开始做,必须在ti时间内把它做完)
          问得到w分的最小用时是多少
解题思路:很像01背包的基本题,但是有一个li分钟前不能AC的限制,因此第i道题必须在最早第(li-ti)时刻做,我们按照l-t递增排序,然后按照经典解法来做
          就行了
*/
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; struct note { int t,v,l; bool operator <(const note &other)const { return l-t
      
       sum) { printf(zhx is naive! ); continue; } sort(node,node+n); up=max(up,ans); memset(dp,0,sizeof(dp)); for(int i=0;i
       
        =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 ,i); flag=1; break; } } if(flag==0) { printf(zhx is naive! ); } } return 0; } 
       
      
     
    
   
  


?

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 are n 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 the ith 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 than w 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.
Input Multiply test cases(less than 50 ). Seek EOF as the end of the file.
For each test, there are two integers n and w separated by a space. ( 1≤n≤30 , 0≤w≤109 )
Then come n lines which contain three integers ti,vi,li . ( 1≤ti,li≤105,1≤vi≤109 )
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 3
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3

Sam
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BZOJ 1531 POI2005 Bank notes 多.. 下一篇HDU 4027 Can you answer these q..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: