Codeforce E. Fire
2 seconds
256 megabytes
standard input
standard output
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 take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-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 item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.
Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.
In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.
3
3 7 4
2 6 5
3 7 6
11
2
2 3
2
5 6 1
3 3 5
1
1
1
In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.
In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
此题虽然A了;
但是感觉自己的做法还是有点问题的;
将这个(x,y,z)这个三元组以y排序;
做一遍背包就行了;
时间复杂度为O(2000*100*100);
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
][],num,maxx,pos,sum,ans[];
struct node{
int t,d,p,pos;
}f[];
bool cmp(node a,node b){
if(a.d==b.d){
a.p<b.p;
}
return a.d<b.d;
}
int main(){
scanf("%d",&n);
num=;
;i<=n;i++){
scanf("%d%d%d",&f[i].t,&f[i].d,&f[i].p);
f[i].pos=i;
f[i].d--;
num=max(num,f[i].d);
}
sort(f+,f+n+,cmp);
memset(dp,-,sizeof(dp));
dp[][]=;
;i<=n;i++){
for(int j=f[i].d;j>=f[i].t;j--){
]!=-&&dp[j-f[i].t][]+f[i].p>=dp[j][]){
;k<=n;k++)
dp[j][k]=dp[j-f[i].t][k];
dp[j][]=dp[j][]+f[i].p;
dp[j][i]=;
}
}
}
maxx=; pos=;
;i<=num;i++)
]>maxx) maxx=dp[i][],pos=i;
printf("%d\n",maxx);
;i<=n;i++)
){
sum++;
ans[sum]=f[i].pos;
}
printf("%d\n",sum);
;i<sum;i++)
printf("%d ",ans[i]);
printf("%d",ans[sum]);
}
Codeforce E. Fire的更多相关文章
- codeforce 35C fire again
2017-08-25 17:04:07 writer:pprp 题目描述: • Codeforces 35C Fire Again• N*M的格子,最开始有K个点 (坐标给定) 开始着火• 每一秒着火 ...
- codeforce E. Fire背包
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- 关于SequeezeNet中的Fire Module
在论文<SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <0.5MB MODEL SIZE>中,作者 ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- Fire
Fire 分析: 首先,明确题意:b1,b2,--,bn 交换为b2,--,bn,b1,但这并不是意味着只能从b1开始交换,(这点从样例中可以看出),并且也不意味着交换的必须是连续的一串,可以是几个单 ...
- Android 轻量级输入校验库:Fire Eye
Fire Eye是一款轻量级简单易用的Android校验库. FireEye 2.0 在 1.0 的基础上,全部重写了代码,并优化了架构,性能上和逻辑上都大大提升.只需要几行代码,即可验证用户输入,并 ...
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- UVA 11624 Fire!(广度优先搜索)
题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...
随机推荐
- Oozie调用Spark实例
oozie调用spark有三样是必须有的: workflow.xml(不可改名) , job.properties(可改名) , jar包(自备). 1.workflow.xml workflow.x ...
- 如何生成转储(dmp)文件--工具篇
转储文件也就是我们常说的dump文件.可以把转储文件看成软件的某个时刻的一个快照.转储文件一般都是在软件出现问题时手动生成或者程序自动生成.下面我们介绍几种生成转储文件的方法. 1. 任务管理器 任务 ...
- html js文字左右滚动插件
自己写过很多插件,但都是直接嵌入在了工程里,从来没有拿出来单独封装成一个文件过,这是第一次,希望是一个良好的开端. 一个文字过长而可以左右滚动的插件 <!DOCTYPE html> < ...
- 字节序转换与结构体位域(bit field)值的读取 Part 2 - 深入理解字节序和结构体位域存储方式
上一篇文章讲解了带位域的结构体,在从大端机(Big Endian)传输到小端机(Little Endian)后如何解析位域值.下面继续深入详解字节序,以及位域存储的方式. (1) 我们知道,存储数字时 ...
- jquery获取json对象中的key小技巧
jquery获取json对象中的key小技巧 比如有一个json var json = {"name" : "Tom", "age" : 1 ...
- 《Java从入门到放弃》JavaSE入门篇:异常
异常!!!看看生活中的异常例子: 正常情况下,从家到公司上班,只需要20分钟!但如果在路上碰到堵车或修路或车突然自燃等问题,那就没办法正常去上班了.其中堵车或修路或车突然自燃等问题就属于异常. 碰到异 ...
- ★浅谈Spanking情节
- vmware 遇到 “无法打开内核设备 \\.\Global\vmx86” 解决
问题描述:vmware没有正常关闭,再次打开使用时蓝屏,在安全模式下再次打开不会蓝屏,但提示"无法打开内核设备 \.\Global\vmx86: 系统找不到指定的文件,你想要安装VMware ...
- Scrapy 爬虫入门 +实战
爬虫,其实很早就有涉及到这个点,但是一直没有深入,今天来搞爬虫.选择了,scrapy这个框架 http://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tut ...
- 201521123055 《Java程序设计》第7周学习总结
1. 本章学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 1.2 解释E remove(int index)源代码 1.3 结合1.1 ...