TOJ 3991 Eat or Study
来源:互联网 发布:要怎么样才能精通java 编辑:程序博客网 时间:2024/04/29 02:08
题目链接:http://acm.tju.edu.cn/toj/showp3991.html
题意:给我们每一天学习的值和吃的值,然后给我们必须要到的学习的值,然后问我们到必须要学习到的值的时候最大满足的吃的值。
一开始一看,这个问题有点像是背包,但是又一个问题那就是我们背包问题的体积和价值是连在一起的,也就是说我们是放入一定体积下同时获得的价值,但现在我们是要么学习,要么吃,看起来就不能用到背包。
但是实际上我们可以转换这个问题,我们把学习的值和吃的值绑定在一起,那么这个时候我们学习的时候同时就能吃,但是实际上我们是不能这样的,所以现在我们获得的吃的值,就相当于总的吃的值,减去我们绑在一起的学习时又同时吃的值,那么为了让吃的值越大,就相当于让我们在满足学习的值时同时得到的吃的值越小,所以我们就可以用背包DP求得最大值。
#include <cstdio>#include <iostream>using namespace std;const int INF = 0x3f3f3f3f;int main(){int t;int p[150],v[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>>p[i]>>v[i];ans+=v[i];}for(int i=0; i<n; i++)for(int j=m; j>=0; j--)if(j <= p[i])dp[j]=min(dp[j],v[i]);elsedp[j]=min(dp[j],dp[j-p[i]]+v[i]);if(dp[m]<INF)cout<<(ans-dp[m])<<endl;elsecout<<"JUMP DOWN!"<<endl;}return 0;}
0 0
- TOJ 3991 Eat or Study
- 3991. Eat or Study toj
- 3991 H. Eat or Study
- rest-work-eat-study-rest-work-eat or rest-rest-work-work-eat-eat..
- 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?(暴力枚举)
- UVA 10273 - Eat or Not to Eat?(暴力)
- UVA10273 - Eat or Not to Eat?(暴力)
- UVA - 10273 Eat or Not to Eat? 暴力
- Eat or Not to Eat? - UVa 10273 暴力
- 浅谈Java设计模式(二十三)解释器模式(Interpreter)
- c3p0、dbcp和proxool的优缺点比较及配置
- Js运动动画系列6--多物体运动-获取样式属性
- NodeJs:module.filename、__filename、__dirname、process.cwd()和require.main.filename 解惑
- java对象占用内存分析
- TOJ 3991 Eat or Study
- HttpURLConnection请求json数据
- android SharedPreferences 使用注意点
- 解决开机提示“error:unknown filesystem grub rescue”的问题
- MySQL5.7 虚拟列实现表达式索引
- 解决IO性能问题的三种方案
- 内核栈 thread_onfo task_struct 三者之间的关系
- apache commons fileupload 生成报告(2016-07-01更新)
- R正态分布+ggplot