codeforces 864 E. Fire(背包+思维)
题目链接:http://codeforces.com/contest/864/problem/E
题解:这题一看就很像背包但是这有3维限制也就是说背包取得先后也会对结果有影响。所以可以考虑sort来降低维度(这是常用的方法)
然后就是简单的有限背包至于这题还要求存下娶了哪些东西可以用vector来存。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#define inf 0X3f3f3f3f
using namespace std;
int dp[];
struct TnT {
int t , d , p , id;
}th[];
bool cmp(TnT a , TnT b) {
return a.d < b.d;
}
vector<int>vc[];
int main() {
int n;
scanf("%d" , &n);
for(int i = ; i < n ; i++) {
scanf("%d%d%d" , &th[i].t , &th[i].d , &th[i].p);
th[i].id = i + ;
}
sort(th , th + n , cmp);
for(int i = ; i <= ; i++) dp[i] = -inf , vc[i].clear();
dp[] = ;
for(int i = ; i < n ; i++) {
for(int j = th[i].d - ; j >= th[i].t ; j--) {
if(dp[j - th[i].t] + th[i].p > dp[j]) {
vc[j].clear();
int len = vc[j - th[i].t].size();
for(int l = ; l < len ; l++) {
vc[j].push_back(vc[j - th[i].t][l]);
}
vc[j].push_back(th[i].id);
dp[j] = dp[j - th[i].t] + th[i].p;
}
}
}
int Max = -inf , pos = ;
for(int i = ; i <= ; i++) {
if(Max < dp[i]) {
Max = dp[i];
pos = i;
}
}
printf("%d\n" , Max);
printf("%d\n" , vc[pos].size());
for(int i = ; i < vc[pos].size() ; i++) {
printf("%d " , vc[pos][i]);
}
puts("");
return ;
}
codeforces 864 E. Fire(背包+思维)的更多相关文章
- CodeForces - 946D Timetable (分组背包+思维)
题意 n天的课程,每天有m个时间单位.若时间i和j都有课,那么要在学校待\(j-i+1\)个时间.现在最多能翘k节课,问最少能在学校待多少时间. 分析 将一天的内容视作一个背包的组,可以预处理出该天内 ...
- Coderfroces 864 E. Fire(01背包+路径标记)
E. Fire http://codeforces.com/problemset/problem/864/E Polycarp is in really serious trouble — his h ...
- codeforces 688 E. The Values You Can Make(01背包+思维)
题目链接:http://codeforces.com/contest/688/problem/E 题解:设dp[s1][s2]表示s1状态下出现s2是否合理.那么s1显然可以更具01背包来得到状态.首 ...
- codeforces 284 E. Coin Troubles(背包+思维)
题目链接:http://codeforces.com/contest/284/problem/E 题意:n种类型的硬币,硬币的面值可能相同,现在要在满足一些限制条件下求出,用这些硬币构成t面值的方案数 ...
- Codeforces Round#522 Div2E(思维,背包,组合数学)
#include<bits/stdc++.h>using namespace std;int a[107];int b[10007][107];int c[107][107];int ma ...
- Codeforces 106 C 多重背包
题目链接:http://codeforces.com/problemset/problem/106/C 根据题意列出式子,设每种蛋糕做了xi个,则对于每种材料bi*xi<=ai. 对于dough ...
- FZU Problem 2214 Knapsack problem(背包+思维转换)
转化思维,把价值当成背包容量,选择最小的花费,从上到下枚举,找到当这个最小的花费. #include<iostream> #include<cstring> #include& ...
- Codeforces 356D 倍增优化背包
题目链接:http://codeforces.com/contest/356/problem/D 思路(官方题解):http://codeforces.com/blog/entry/9210 此题需要 ...
- codeforce E. Fire背包
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- maven-build-downloading
1. 场景描述 maven库用的是公司私服和阿里云结合的方式(maven多仓库配置),本项目maven依赖的有其他项目组的jar包(单点登录),但是天有不测风云,依赖单点登录的好几个jar包,在编译( ...
- l命令练习题1
1.创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令) [root@localhost ~]# mkdir -p /guanli/zonghe | mk ...
- 数字麦克风PDM信号采集与STM32 I2S接口应用
数字麦克风采用MEMS技术,将声波信号转换为数字采样信号,由单芯片实现采样量化编码,一般而言数字麦克风的输出有PDM麦克风和PCM麦克风,由于PDM麦克风结构.工艺简单而大量应用,在使用中要注意这二者 ...
- 解决跨域session 同步问题
跨域来源:(前端站点和后端API布署到不同的站点) 解决方案 一.服务端设置 1.配置允许跨域请求 public class BaseAction { /** * 支持跨域请求 * @author f ...
- GitHub项目:jkrasnay/sqlbuilder的使用
http://www.jianshu.com/p/7f099b8cf5f0 技术选型: 在报表查询时,通常需要做可以动态添加的条件 在老项目中使用的是一种Tcondition的对象分装sql impo ...
- RE最全面的正则表达式----终结篇 特殊处理
三.特殊需求表达式 Email地址:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0- ...
- RocketMQ中PullConsumer的启动源码分析
通过DefaultMQPullConsumer作为默认实现,这里的启动过程和Producer很相似,但相比复杂一些 [RocketMQ中Producer的启动源码分析] DefaultMQPullCo ...
- Spring 集成Kafka(完整版)
前面的文章我们已经完成了Kafka基于Zookeeper的集群的搭建了.Kafka集群搭建请点我.记过几天的研究已经实现Spring的集成了.本文重点 jar包准备 集成是基于spring-integ ...
- MapReduce on Yarn运行原理
一.概念综述 MapReduce是一种可用于数据处理的编程模型(或计算模型),该模型可以比较简单,但想写出有用的程序却不太容易.MapReduce能将大型数据处理任务分解成很多单个的.可以在服务器集群 ...
- 洛谷 P1939 矩阵加速(数列)
题意简述 \(a[1]=a[2]=a[3]=1\) \(a[x]=a[x−3]+a[x−1](x>3)\) 求a数列的第n项对1000000007取余的值. 题解思路 矩阵加速 设\[ F=\b ...