3991 H. Eat or Study
来源:互联网 发布:淘宝优惠券去哪里领 编辑:程序博客网 时间:2024/05/14 18:13
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
3
2 3
3 2
3 3
3 10
3 2
3 3
3 3
3 5
2 10
2 100
2 50
Sample Output
3
JUMP DOWN!
0
题意:给出你每天读书能增加的智慧和吃东西能增加的体重,问你如何在达到智慧要求的同时增最多的重量。
dp来做。
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>using namespace std;int w[105],v[105],dp[105][105];int main (void){ int t; cin>>t; while(t--) { memset(dp,-1,sizeof(dp)); memset(w,0,sizeof(w)); memset(v,0,sizeof(v)); int n,m; scanf("%d %d",&n,&m); dp[0][0]=0; for(int i=1;i<=n;i++) { scanf("%d %d",&v[i],&w[i]); } //dp[i][j]表示第i天学了j知识时候的体重 for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { if(dp[i-1][j]!=-1)//判断前一个状态能否成立 { dp[i][j]=max(dp[i][j],dp[i-1][j]+w[i]);//今天不读书 //昨天吃了的重量和昨天没吃,今天吃了的重量 int nxt=j+v[i]>m?m:j+v[i]; //今天读书,如果超过了m,就按照m来算 dp[i][nxt]=max(dp[i-1][j],dp[i][nxt]); //昨天读了书的重量和昨天没读书,今天读了书的重量 } } } if(dp[n][m]==-1) printf("JUMP DOWN!\n"); else printf("%d\n",dp[n][m]); } return 0;}
- 3991 H. Eat or Study
- TOJ 3991 Eat or Study
- 3991. Eat or Study toj
- rest-work-eat-study-rest-work-eat or rest-rest-work-work-eat-eat..
- Problem H: Eat Candy
- Problem H: Eat Candy
- Problem H: Eat Candy
- Problem H: Eat Candy
- 10273 - Eat or Not to Eat?
- eat out or eat in 吃货英语
- ZOJ-1236 Eat or Not to Eat?
- uva 10273 Eat or Not to Eat?
- UVa10273 Eat or Not to Eat?
- UVA - 10273 Eat or Not to Eat?
- UVA 10273 Eat or Not to Eat?
- 1587. Eat or Be Eaten
- Eat at home or restaurant
- uva 10273 - Eat or Not to Eat?(暴力枚举)
- 经典进程的同步问题-生产者与消费者
- 在 Web 项目中应用 Apache Shiro
- SCAU Individual Contest #1 (未更新完)
- Ubuntu下为Firefox安装Adobe Flash Player
- 使用achartengine 画图表时属性设置
- 3991 H. Eat or Study
- Android开发——Retrofit2.0 工具类
- Java 学习笔记(0x01) 数据类型转换
- A - The Suspects
- H - Wireless Network
- B - Ubiquitous Religions
- java多线程(一)多线程基础
- synchronized 的用法
- Linux 同步网络时间