背包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)的更多相关文章

  1. Codeforces 864E Fire(DP)

    题目链接 Fire 题意 有n个物品,每个物品的挽救时间代价为ti, 消失时刻为di, 价值为pi. 如果要救某个物品,必须在他消失之前救出来. 同一时刻最多只能救一件物品. 当前耗时为当前已经救出的 ...

  2. 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 如果只是单纯模拟肯定会超时 ...

  3. Codeforces 864E - Fire(dp)

    原题连接:http://codeforces.com/problemset/problem/864/E 题意:一个人想从大火中带走一些东西.每次他只能带一个,耗时ti ,价值为pi, 当总时间超过di ...

  4. H - Fire CodeForces - 864E 01背包

    https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影 ...

  5. [Codeforces 864E]Fire

    Description Polycarp is in really serious trouble — his house is on fire! It's time to save the most ...

  6. 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/ ...

  7. Codeforces 730J:Bottles(背包dp)

    http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...

  8. 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 \( ...

  9. Codeforces 922 E Birds (背包dp)被define坑了的一题

    网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...

随机推荐

  1. 数据库Mysql的学习(一)-启动和进入

    数据库:按照数据结构来组织储存和管理数据的仓库. Mysql是关系型数据库管理系统 Mysql安装好之后... mysql的启动 1:通过控制面板里的”服务“找到mysql右键启动即可 2:开始菜单搜 ...

  2. python常用命令—ipython3环境下获取某个文件夹下的文件列表

    import os os.listdir('文件夹路径')

  3. c++容器 STL

    2019-01-24 22:30:32 记录学习PAT的一些知识,有待更新 注:本文是对Algorithm 算法笔记 的总结 C++标准库模板(Standard Template Library,ST ...

  4. LeetCode 169. Majority Element - majority vote algorithm (Java)

    1. 题目描述Description Link: https://leetcode.com/problems/majority-element/description/ Given an array ...

  5. POJ 1228 Grandpa's Estate(凸包唯一性判断)

    Description Being the only living descendant of his grandfather, Kamran the Believer inherited all o ...

  6. Thunder团队第二周 - Scrum会议5

    Scrum会议5 小组名称:Thunder 项目名称:爱阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...

  7. II 3.1 连接到服务器

    II 3.1 连接到服务器 package socket; import java.io.IOException; import java.io.InputStream; import java.ne ...

  8. lintcode-18-带重复元素的子集

    带重复元素的子集 给定一个可能具有重复数字的列表,返回其所有可能的子集 注意事项 子集中的每个元素都是非降序的 两个子集间的顺序是无关紧要的 解集中不能包含重复子集 样例 如果 S = [1,2,2] ...

  9. 3dContactPointAnnotationTool开发日志(十二)

      因为ReferenceImage的锚点是固定的左下角,缩放时controller面板也会跟着动.为了使Scale的时候controller上的slider不会远离指针,于是把controller固 ...

  10. html5 download all in one

    html5 download all in one HTML5 download & Fetch API & File API & Blob https://scarletsk ...