3991. Eat or Study toj

來源:互聯網
上載者:User

3991.   Eat or Study

Time Limit: 1.0 Seconds   Memory Limit:65536K
Total Runs: 127   Accepted Runs:43

 

 

As a ACMer, Yan is good at arrange his schedule. On every morning of the term, he will have a choice: study or eating.
Especially, Yan can only do one thing everyday, and he have to do one thing everyday. That means Yan cannot both study and eat in one day, and he cannot do nothing on that day.If he choose study on the ith day,
he will get xi knowledge points,and if he choose eating, his weight will increase yi points.After the term, Yan must face the final exam. If his knowledge points
is less than m, he will fail in the exam. Now Yan wants to know the maximal value he can increase his weight without fail in the exam.

Input

The first line of input is a integer t (t≤100), means there are t test case.
For each test case, there are two integers in the first line, n(n≤100)  and m(m≤100). n means there are n days in the term. m means that Yan have to get m knowledges when he face the final exam, or he will fail.Then n lines follow, each line contains two integer,
xi(0≤xi≤100) and yi(0≤yi≤100).  xi
means he will get  xi knowledge points if he study in the ith day, yi means he will get yi
weight points if he eats in the ith day.

Output

For each test case, there is only one line.
If Yan can pass the exam, output the max weight he can increase without fail.
If Yan can't pass the exam, output "JUMP DOWN!"

Sample Input

32 33 23 33 103 23 33 33 52 102 1002 50

Sample Output

3JUMP DOWN!0

dp[i]表示能滿足i點知識點的情況下取得最小的重量

大俠的代碼

 

#include<cstdio>#include<iostream>using namespace std;#define INF 100001int main(){int t;int x[150],y[150];int dp[150];cin>>t;while(t--){int n,m;int ans=0;cin>>n>>m;for(int i=0;i<=m;i++)dp[i]=INF;for(int i=0;i<n;i++){cin>>x[i]>>y[i];ans+=y[i];}for(int i=0;i<n;i++)for(int j=m;j>=0;j--)if(j-x[i]<=0)dp[j]=min(dp[j],y[i]);elsedp[j]=min(dp[j],dp[j-x[i]]+y[i]);if(dp[m]<INF)cout<<(ans-dp[m])<<endl;elsecout<<"JUMP DOWN!"<<endl;}return 0;}

 

 錯誤碼 還沒找出哪裡錯

#include<cstdio>#include<iostream>using namespace std;#define INF 100001int main(){int t;int x[150],y[150];int dp[15000];cin>>t;while(t--){int n,m;int ans=0;int sum=0;cin>>n>>m;for(int i=0;i<n;i++){cin>>x[i]>>y[i];ans+=y[i];sum+=x[i];}for(int i=0;i<=sum;i++)dp[i]=INF;dp[0]=0;for(int i=0;i<n;i++)for(int j=sum;j>=x[i];j--)if(dp[j-x[i]]<INF)dp[j]=min(dp[j],dp[j-x[i]]+y[i]);int flag=1;for(int i=m;i<=sum;i++)if(dp[i]<=ans){flag=0;cout<<(ans-dp[i])<<endl;break;}if(flag)cout<<"JUMP DOWN!"<<endl;}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.