题目链接: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. .NET Core on K8S学习实践系列文章索引(Draft版)

    一.关于这个系列 自从去年(2018年)底离开工作了3年的M公司加入X公司之后,开始了ASP.NET Core的实践,包括微服务架构与容器化等等.我们的实践是渐进的,当我们的微服务数量到了一定值时,发 ...

  2. Intellij IDEA 中 使用 Git

    前一段时间使用 Microsoft 的 Visual Studio Code 中使用 Git 对前端项目进行项目代码的开发提交. 使用后感觉挺好的,用的多了也觉得挺简单方便的. 现在需要在 Intel ...

  3. git指令-未完待更新

    git指令 1. $ git config --global user.name "Your Name" $ git config --global user.email &quo ...

  4. Currency Exchange POJ1860

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  5. pytest

    pytest可以生成多种样式的结果:1.生成JunitXML格式测试报告:命令: --junitxml=path(相对路径)2.生成result log 格式的测试报告: 命令:--resultlog ...

  6. 【Java例题】2.7找零钱

    7.为顾客找零钱时,希望选用的纸币张数最少. 例如73元,希望零钱的面值为五十元1张,二十元1张,一元3张. 设零钱面值有五十元.二十元.十元.五元和一元, 请编写程序,用户输入100以下的数, 计算 ...

  7. LeetCode :2.两数相加 解题报告及算法优化思路

    题目连接:2.两数相加 题意 题目难度标为 中等, 因为题意上有一部分理解难度,以及需要数据结构的链表基础. 还不知道到链表的童鞋可以粗略的看下百度百科或者是翻出数据结构的书看一看,通俗一点的语言来解 ...

  8. NAS

    NAS, Network Attached Storage, 网络附属存储, 简单来说就是连接在网络上, 可以存储资料的装置.可以用来做私有网盘,同步各种设备的照片.视频.音频和文件. 常见的 NAS ...

  9. zuul 路由网关 微服务架构系统中

    在微服务架构中,基本包含以下常见的组件.服务注册与发现.服务消费.负载均衡.断路器.只能路由.配置管理等.一个简单的微服务架构系统如下 一.Zuul简介 Zuul的主要功能是路由转发和过滤器.路由功能 ...

  10. vue 使用gojs绘制简单的流程图

    在vue项目中需要展示工作流进度,可以使用的流程图插件很多 flowchart.js  http://adrai.github.io/flowchart.js/ , 基于SVG创建Flow Chart ...