Codeforces 864E Fire(背包DP)
背包DP,决策的时候记一下 jc[i][j]=1 表示第i个物品容量为j的时候要选,输出方案的时候倒推就好了
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
struct poi{int t,ddl,p,id;}a[maxn];
int n,top,ansi,cnt;
int f[][maxn],st[maxn],jc[][maxn];
bool cmp(poi a,poi b){return a.ddl<b.ddl;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d%d%d",&a[i].t,&a[i].ddl,&a[i].p);
a[i].id=i;
}
sort(a+,a++n,cmp);
for(int i=;i<=n;i++)
{
for(int j=;j<a[i].t;j++)f[i][j]=f[i-][j];
for(int j=a[i].t;j<=a[i].ddl-;j++)
{
f[i][j]=f[i-][j];
if(f[i-][j-a[i].t]+a[i].p>f[i][j])
{
f[i][j]=f[i-][j-a[i].t]+a[i].p;
jc[i][j]=;
}
}
}
int ans=;
for(int i=;i<a[n].ddl;i++)
if(f[n][i]>ans)ans=f[n][i],ansi=i;
for(int i=n;i&&ansi;i--)
if(jc[i][ansi])cnt++,st[++top]=i,ansi-=a[i].t;
printf("%d\n%d\n",ans,cnt);
for(;top;top--)printf("%d ",a[st[top]].id);
}
Codeforces 864E Fire(背包DP)的更多相关文章
- Codeforces 864E Fire(DP)
题目链接 Fire 题意 有n个物品,每个物品的挽救时间代价为ti, 消失时刻为di, 价值为pi. 如果要救某个物品,必须在他消失之前救出来. 同一时刻最多只能救一件物品. 当前耗时为当前已经救出的 ...
- Codeforces 946 课程表背包DP 数位DFS构造
A B 给你A,B 两个数 1.a=0 OR b=0 break 2.a>=2b a=a-2b 3.b>=2a b=b-2a 如果只是单纯模拟肯定会超时 ...
- Codeforces 864E - Fire(dp)
原题连接:http://codeforces.com/problemset/problem/864/E 题意:一个人想从大火中带走一些东西.每次他只能带一个,耗时ti ,价值为pi, 当总时间超过di ...
- H - Fire CodeForces - 864E 01背包
https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影 ...
- [Codeforces 864E]Fire
Description Polycarp is in really serious trouble — his house is on fire! It's time to save the most ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- Codeforces 730J:Bottles(背包dp)
http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
- Codeforces 922 E Birds (背包dp)被define坑了的一题
网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...
随机推荐
- 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)
题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...
- uvaoj 489 - Hangman Judge(逻辑+写代码能力)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Linux命令应用大词典-第46章 其他命令
46.1 mkfontdir:创建X字体文件的索引 46.2 dumpiso:转储IEEE 1394同步信道的数据包 46.3 iconv:转换文件编码 46.4 hash:显示和删除哈希表 46.5 ...
- darknet 识别获取结果
在examples/darknet.c文件中若使用detect命令可以看到调用了test_detector. ... else if (0 == strcmp(argv[1], "detec ...
- Siki_Unity_3-13_编程内功修炼-算法
Unity 3-13 编程内功修炼 -- 算法 任务1&2:课程介绍 主要算法: 分治法 堆排序 二叉树 动态规划 贪心算法 图 任务3:分治算法 -- Divide and Conquer ...
- 剑指offer-二叉树搜索树与双向链表25
题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. class Solution: def Convert(self, pRo ...
- Keil sct分散加载文件
官方说明:http://www.keil.com/support/man/docs/armlink/armlink_pge1401393372646.htm
- hosts_allow配置了却不生效
hosts_allow配置了却不生效 配置了两台白名单的机器,一台生效一台不生效,google后的结果都是更新libwrap.so 安装openssh等等..(问题还是没有解决) 经过对比发现,原来 ...
- Martin Fowler关于IOC和DI的文章(原版)
Inversion of Control Containers and the Dependency Injection pattern In the Java community there's b ...
- HDU 2114 Calculate S(n)
http://acm.hdu.edu.cn/showproblem.php?pid=2114 Problem Description Calculate S(n). S(n)=13+23 +33 +. ...