HDU 5188 zhx and contest(帶限制條件的 01背包),hduzhx

來源:互聯網
上載者:User

HDU 5188 zhx and contest(帶限制條件的 01背包),hduzhx

Problem DescriptionAs 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 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. 
InputMultiply 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) 
OutputFor 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!
 

題意:


  1. 有n道題i題用時ti秒,得分vi,在li時間點之前不能做出來,而且一道題不能分開幾次做(一旦開始做,必須在ti時間內把它做完) 
  2.           問得到w分的最小用時是多少 


思路: 把題目按開始做的先後順序排序,然後o1背包





#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8typedef __int64 ll;#define fre(i,a,b)  for(i = a; i <b; i++)#define free(i,b,a) for(i = b; i >= a;i--)#define mem(t, v)   memset ((t) , v, sizeof(t))#define ssf(n)      scanf("%s", n)#define sf(n)       scanf("%d", &n)#define sff(a,b)    scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf          printf#define bug         pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 100005int dp[30*N];struct stud{ int t,l,va; bool operator < (const stud a) const {    return l-t<a.l-a.t; }}f[40];int all,sum;int n,m;void solve(){int i,j;sort(f,f+n);int te;mem(dp,0);fre(i,0,n)  free(te,all,f[i].l)    if(te>=f[i].t)     dp[te]=max(dp[te],dp[te-f[i].t]+f[i].va);fre(i,0,all)  if(dp[i]>=m) break;pf("%d\n",i);}int main(){int i,j;while(~sff(n,m)){sum=all=0;int temp=0;fre(i,0,n) { sfff(f[i].t,f[i].va,f[i].l);    all+=f[i].t;    temp=max(temp,f[i].l);    sum+=f[i].va; }     if(sum<m) { pf("zhx is naive!\n"); continue; } all=max(all,temp); solve();}     return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.