Codeforces Round #436 E. Fire
来源:互联网 发布:为什么黑客都用python 编辑:程序博客网 时间:2024/06/05 21:00
Title:Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would taketi seconds to savei-th item. In addition, for each item, he estimated the value ofdi — the moment after which the itemi will be completely burned and will no longer be valuable for him at all. In particular, ifti ≥ di, theni-th item cannot be saved.
Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the itema will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.
Each of the following n lines contains three integersti, di, pi (1 ≤ ti ≤ 20,1 ≤ di ≤ 2 000,1 ≤ pi ≤ 20) — the time needed to save the itemi, the time after which the item i will burn completely and the value of item i.
#include<bits/stdc++.h>using namespace std;struct node{int t,d,p; int ind; bool operator<(const node& n) const{ return d<n.d;}}item[110];int dp[105][2005],path[105][2005];int main(){int n;while(~scanf("%d",&n)){for(int i=1;i<=n;i++){scanf("%d %d %d",&item[i].t,&item[i].d,&item[i].p);item[i].ind=i;}sort(item+1,item+n+1);memset(dp,0,sizeof(dp));memset(path,0,sizeof(path));for(int i=1;i<=n;i++){for(int j=0;j<item[i].d;j++){//重要点,因为超出毁掉时间的并没有意义 dp[i][j]=dp[i-1][j];if(j<item[i].t) continue;if(dp[i-1][j-item[i].t]+item[i].p>dp[i][j]){dp[i][j]=dp[i-1][j-item[i].t]+item[i].p;path[i][j]=1;}}} //dp[n][item[n].d-1]并非最大值,值得思考 ,因为第23行的缘故,忽略了毁掉时间点后的价值, //item[n].d-1也有可能是被忽略的点 int maxj=0,pos;for(int i=0;i<2001;i++){if(dp[n][i]>maxj){maxj=dp[n][i];pos=i;}}printf("%d\n",maxj);vector<int> v;for(int i=n;i>=1;i--){if(path[i][pos]){v.push_back(item[i].ind);pos-=item[i].t;}}printf("%d\n",v.size());for(int i=v.size()-1;i>=0;i--) printf("%d ",v[i]);puts("");}return 0;}就这样了,就算把这题过了。但总觉得不够好,希望大家讨论一下。
- Codeforces Round #436 E. Fire
- Codeforces Round #436 (Div. 2) E. Fire
- Codeforces Round #436 (Div. 2)E.Fire
- Codeforces Round #436 (Div. 2)E. Fire
- Codeforces Round #436 (Div. 2) E. Fire
- Codeforces Round #436 (Div. 2) E fire DP
- Codeforces Round #436 (Div. 2) 864E. Fire
- Codeforces Round #436 E.Fire(01背包 + 输出路径)
- Codeforces 864E (Codeforces Round #436 (Div. 2)) E. Fire 背包输出路径
- Codeforces Round #436 (Div. 2)-E-Fire(01背包输出路径)
- Codeforces Round #436 (Div. 2) E. Fire(背包DP+输出路径)
- Codeforces Round #436 (Div. 2) E. Fire(01背包+输出路径)
- Codeforces Round #436 (Div. 2)-背包&排序&输出状态-E. Fire
- Codeforces Round #436 (Div. 2) E. Fire (有放入顺序有关的01背包)
- 【01背包 && 记录路径 && 约束】Codeforces Round #436 (Div. 2) E. Fire
- codeforces 864E Fire
- CodeForces 864E Fire
- Codeforces Round #436 (Div. 2) Fire
- 多线程(3)
- Linux下go开发环境的安装
- 数据结构实验之栈与队列六:下一较大值(二)
- Makefile构建工程设计——工程组织Makefile的嵌套
- LightOJ_1011Marriage Ceremonies
- Codeforces Round #436 E. Fire
- java-面试题判断题答案及解析
- 数据结构实验之栈与队列八:栈的基本操作
- CentOS yum 源的配置与使用
- matlab的imshow()如何以合适大小显示图片
- jQuery学习笔记
- 1.2.4打印方法与变量i--的问题
- WEB_03_JavaScript_JS基本语法_第二讲
- 数据结构实验之栈与队列九:行编辑器