H - Fire CodeForces - 864E 01背包
https://codeforces.com/problemset/problem/864/E
这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影响到之前的。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 2e3 + ; struct node
{
int t, p, d, id;
}exa[maxn]; bool cmp(node a,node b)
{
return a.d < b.d;
} int G[][];
int dp[]; int main()
{
int n;
int V = ;
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d%d%d", &exa[i].t, &exa[i].d, &exa[i].p);
exa[i].id = i;
V = max(V, exa[i].d);
}
sort(exa + , exa + + n, cmp);
//for (int i = 1; i <= n; i++) printf("www %d %d %d\n", exa[i].t, exa[i].d, exa[i].p);
int ex = , x = , y = ;
for (int i = ; i <= n; i++)
{
for (int j = exa[i].d-; j >= exa[i].t; j--)
{
if (dp[j - exa[i].t] + exa[i].p > dp[j])
{
dp[j] = dp[j - exa[i].t] + exa[i].p;
G[i][j] = ;
}
if(dp[j]>ex)
{
ex = dp[j];
x = i, y = j;
}
}
}
printf("%d\n", ex);
stack<int>ans;
int i = x, j = y;
while (i > )
{
if(G[i][j])
{
ans.push(exa[i].id);
j -= exa[i].t;
}
i -= ;
}
printf("%d\n", (int)ans.size());
while(!ans.empty())
{
printf("%d ", ans.top());
ans.pop();
}
printf("\n");
return ;
}
H - Fire CodeForces - 864E 01背包的更多相关文章
- Codeforces 336C 0-1背包
题意:每个水果有两个值,一个美味度 a,一个卡路里 b,从中挑选一些,要求 sum(aj) / sum(bj) = k,使得 sum(a) 最大. 分析:没有那个条件就是一个01背包,可以转换,对公式 ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) D 多重排列 + 反向01背包 + 离线处理
https://codeforces.com/contest/1111/problem/D 多重排列 + 反向01背包 题意: 给你一个字符串(n<=1e5,n为偶数),有q个询问,每次询问两个 ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses —— DP(01背包)
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable ...
- Coderfroces 864 E. Fire(01背包+路径标记)
E. Fire http://codeforces.com/problemset/problem/864/E Polycarp is in really serious trouble — his h ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...
- Codeforces 741B:Arpa's weak amphitheater and Mehrdad's valuable Hoses(01背包+并查集)
http://codeforces.com/contest/741/problem/B 题意:有 n 个人,每个人有一个花费 w[i] 和价值 b[i],给出 m 条边,代表第 i 和 j 个人是一个 ...
- Codeforces 730 J.Bottles (01背包)
<题目链接> 题目大意: 有n个瓶子,各有水量和容量.现在要将这写瓶子里的水存入最少的瓶子里.问你最少需要的瓶子数?在保证瓶子数最少的情况下,要求转移的水量最少. 解题分析:首先,最少的瓶 ...
- CodeForces - 366C Dima and Salad (01背包)
题意:n件东西,有属性a和属性b.要选取若干件东西,使得\(\frac{\sum a_j}{\sum b_j} = k\).在这个条件下,问\(\sum a_j\)最大是多少. 分析:可以将其转化为0 ...
随机推荐
- redis 浅谈事务
写在前面的话 之前在某个网站上看到一个问题:redis在什么情况下出现事务不会滚的情况,以此为由并结合redis官方文档整理这边笔记.不足之处,请指出,谢谢. 事务 redis支持事务,提供两条重要的 ...
- Git应用详解第十讲:Git子库:submodule与subtree.md
前言 前情提要:Git应用详解第九讲:Git cherry-pick与Git rebase 一个中大型项目往往会依赖几个模块,git提供了子库的概念.可以将这些子模块存放在不同的仓库中,通过submo ...
- Redisson 实现分布式锁的原理分析
写在前面 在了解分布式锁具体实现方案之前,我们应该先思考一下使用分布式锁必须要考虑的一些问题. 互斥性:在任意时刻,只能有一个进程持有锁. 防死锁:即使有一个进程在持有锁的期间崩溃而未能主动释放锁, ...
- CKEditor与定制
一 开始使用 官网 基本示例: 搭建服务器(这里使用apache) 下载standard的ckeditor解压放在apache的htdocs的目录下 在htdoc下面新建index.html,写入代码 ...
- weblogic漏洞(一)----CVE-2017-10271
WebLogic XMLDecoder反序列化漏洞(CVE-2017-10271) 0x01 漏洞原因: Weblogic的WLS Security组件对外提供webservice服务,其中使用了XM ...
- 使用User Agent和代理IP隐藏身份
一.为何要设置User Agent 有一些网站不喜欢被爬虫程序访问,所以会检测连接对象,如果是爬虫程序,也就是非人点击访问,它就会不让你继续访问,所以为了要让程序可以正常运行,需要隐藏自己的爬虫程序的 ...
- Nginx(1)---安装及基础命令
一.简述 Nginx是一个高性能WEB服务器,除它之外Apache.Tomcat.Jetty.IIS,它们都是Web服务器 Nginx 相对基它WEB服务有什么优势:Tomcat.Jetty 面向j ...
- 数据结构(C语言版)---查找
1.查找表:同一类型的数据元素构成的集合. 2.对查找表进行的操作:查询某特定元素.检索满足条件的元素的属性.插入元素.删除元素. 1)若对查找表进行的操作只涉及前两种,则为静态查找表:需要进行插入和 ...
- 关于“xxx”object is not callable的异常
参考博文:https://blog.csdn.net/yitiaodashu/article/details/79016671 所谓callable对象是指一个后边可以加()的对象,比如函数, 所以这 ...
- synchronized 的实现原理
加不加 synchronized 有什么区别? synchronized 作为悲观锁,锁住了什么? synchronized 代码块怎么用 前面 3 篇文章讲了 synchronized 的同步方法和 ...