题目链接: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. js实现3D切换效果

    今天分享一个3d翻转动画效果,js+css3+h5实现,没有框架. 先看下html部分: <div class="box"> <ul> <li> ...

  2. scrapyd schedule.json setting 传入多个值

    使用案例: import requests adder='http://127.0.0.1:6800' data = { 'project':'v1', 'version':'12379', 'set ...

  3. SpringMVC学习笔记之---深入使用

    SpringMVC深入使用 (一)基于XML配置的使用 (1)配置 1.SpringMVC基础配置 2.XML配置Controller,HandlerMapping组件映射 3.XML配置ViewRe ...

  4. 佳木斯集训Day4

    Day4的出题人好毒瘤啊!!! T1我打表过的,正解现在也不会 #include <bits/stdc++.h> #define MAXN 10050 #define ll long lo ...

  5. jq css3实现跑马灯+大转盘

    前端效果, <!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" con ...

  6. ssm执行流程

    SSM运行流程 1:服务器启动,创建springmvc的前端控制器DispatcherServlet,创建Spring容器对象. 加载spring-servlet.xml .applicationCo ...

  7. 微信小程序项目总结-记账小程序(包括后端)

    一.小程序部分 这是理财系统的前端,江苏海洋大学微信小程序比赛,最后获得了一等奖 GitHub:https://github.com/GeorgeLeoo/finance 1. 项目描述 (1). 此 ...

  8. 最大层内元素和----leetcode周赛150_1002

    题目描述: 给你一个二叉树的根节点 root.设根节点位于二叉树的第 1 层,而根节点的子节点位于第 2 层,依此类推. 请你找出层内元素之和 最大 的那几层(可能只有一层)的层号,并返回其中 最小 ...

  9. Leetcode solution 124: Binary Tree Maximum Path Sum

    Problem Statement Given a non-empty binary tree, find the maximum path sum. For this problem, a path ...

  10. Git revert -m

    这其实是个非常简单的指令,甚至用AS,直接右键操作不需要两秒钟 但今天使用命令行的方式操作的时候居然发现了点不一样的地方: 如下我希望revert某个commit,找到了它的id,跑一下命令之后居然发 ...