题目链接: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(背包+思维)的更多相关文章

  1. CodeForces - 946D Timetable (分组背包+思维)

    题意 n天的课程,每天有m个时间单位.若时间i和j都有课,那么要在学校待\(j-i+1\)个时间.现在最多能翘k节课,问最少能在学校待多少时间. 分析 将一天的内容视作一个背包的组,可以预处理出该天内 ...

  2. Coderfroces 864 E. Fire(01背包+路径标记)

    E. Fire http://codeforces.com/problemset/problem/864/E Polycarp is in really serious trouble — his h ...

  3. codeforces 688 E. The Values You Can Make(01背包+思维)

    题目链接:http://codeforces.com/contest/688/problem/E 题解:设dp[s1][s2]表示s1状态下出现s2是否合理.那么s1显然可以更具01背包来得到状态.首 ...

  4. codeforces 284 E. Coin Troubles(背包+思维)

    题目链接:http://codeforces.com/contest/284/problem/E 题意:n种类型的硬币,硬币的面值可能相同,现在要在满足一些限制条件下求出,用这些硬币构成t面值的方案数 ...

  5. Codeforces Round#522 Div2E(思维,背包,组合数学)

    #include<bits/stdc++.h>using namespace std;int a[107];int b[10007][107];int c[107][107];int ma ...

  6. Codeforces 106 C 多重背包

    题目链接:http://codeforces.com/problemset/problem/106/C 根据题意列出式子,设每种蛋糕做了xi个,则对于每种材料bi*xi<=ai. 对于dough ...

  7. FZU Problem 2214 Knapsack problem(背包+思维转换)

    转化思维,把价值当成背包容量,选择最小的花费,从上到下枚举,找到当这个最小的花费. #include<iostream> #include<cstring> #include& ...

  8. Codeforces 356D 倍增优化背包

    题目链接:http://codeforces.com/contest/356/problem/D 思路(官方题解):http://codeforces.com/blog/entry/9210 此题需要 ...

  9. codeforce E. Fire背包

    E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. 【JDK】JDK源码分析-LinkedList

    概述 相较于 ArrayList,LinkedList 在平时使用少一些. LinkedList 内部是一个双向链表,并且实现了 List 接口和 Deque 接口,因此它也具有 List 的操作以及 ...

  2. codeforces 213div(2) 365 A.Good Number 365 B.The Fibonacci Segment

    #include <stdio.h> #include <string.h> bool vis[11]; int n, k; bool judge(int x) { memse ...

  3. Oracle DBLink跨数据库访问SQL server数据同步 踩坑实录

    项目需求:这里暂且叫A公司吧,A公司有一套人事管理软件,需要与我们公司的软件做人员信息同步,A公司用的是SQL server数据库,我们公司用的Oracle,接口都不会开发(一万句"fuck ...

  4. Java代码计算运行时间

    突然想准确的测试一下Java代码的执行时间,在网上找了一会.发现基本有以下两种方法:第一种是以毫秒为单位计算的. Java代码 //伪代码 long startTime=System.currentT ...

  5. JavaScript ES6和ES5闭包的小demo

    版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons) 可能有些小伙伴不知道ES6的写法,这儿先填写一个小例子 let conn ...

  6. 【Java笔记】【Java核心技术卷1】chapter3 D5运算符

    package chapter3; import java.math.*; //引入数学类 //枚举类型 enum Size{SMALL,MEDIUM,LARGE}; public class D5运 ...

  7. vue之手把手教你写日历组件

    ---恢复内容开始--- 1.日历组件 1.分析功能:日历基本功能,点击事件改变日期,样式的改变 1.结构分析:html 1.分为上下两个部分 2.上面分为左按钮,中间内容展示,右按钮 下面分为周几展 ...

  8. 减谈迷宫C++

    今天老师让做了个迷宫问题,我一看到就发现和我之前写过的一个程序是一样 的,但是在后来编写的时候有一个地方搞错了,最后下课了我还是没有正确的编写好,然后今天回来之后自己有看了一下,现在已经解决了. #i ...

  9. 给debian的docker容器添加crontab定时任务

    现在大部分的docke镜像是基于debian # cat /etc/issue Debian GNU/Linux 9 \n \l Docker容器是不支持后台服务的,像systemctl servic ...

  10. 解决 Nginx 代理Apex慢的问题

    前不久用 Nginx 代理 Oracle 的 Apex 速度非常慢,我之前Nginx 配置如下: server{ listen 80; server_name localhost; client_ma ...