#436 Div2 E

题意

某人的房子着火了,现在有 \(n\) 件物品待抢救,每件物品有抢救需要的时间和自身的价值,以及过多长时间物品会损坏。问最多一共可以抢救价值多少的物品?

分析

看数据就知道是 \(DP\) 了。

考虑怎么去 \(DP\) ,因为给出物品是无序的,需要我们自己去决定顺序,显然不能直接去枚举 \(n\) 个物品,注意到时间是天然有序的,很容易想到去枚举时间,\(dp[i]\) 表示到时间 \(i\) 为止的物品价值总和。因为每种物品只能选择一次,所以在枚举的过程中有 01 背包的思想。

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, dp[2002];
struct P {
int i, t, p;
};
vector<P> G[2002];
vector<int> V[2002];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
int t, d, p;
cin >> t >> d >> p;
G[d].push_back(P{i + 1, t, p});
}
for(int i = 2; i < 2002; i++) {
if(G[i].size() > 0) {
for(auto v : G[i]) {
for(int j = i; j > v.t; j--) {
int tmp = dp[j - v.t] + v.p;
if(dp[j] < tmp) {
dp[j] = tmp;
V[j] = V[j - v.t];
V[j].push_back(v.i);
}
}
}
}
if(dp[i] < dp[i - 1]) {
dp[i] = dp[i - 1];
V[i] = V[i - 1];
}
}
cout << dp[2001] << endl;
cout << V[2001].size() << endl;
for(auto i : V[2001]) cout << i << " ";
cout << endl;
return 0;
}

Codeforces #436 Div2 E的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. 8086汇编语言 调用声卡播放wav文件(sound blaster)

    开更 大概最后做了一个能播放无损音乐(无压缩.不需解码)的播放器 原理是基于dosbox的模拟声卡,通过硬件之间的相互通讯做到的 关于详细内容接下来再讲. 一.从dosbox入手 我们知道cpu可以直 ...

  2. Windows关机过程分析与快速关机

    原文链接:http://blog.csdn.net/flyoxs/article/details/3710367 Windows开机和关机慢,很多时候慢得令人抓狂.特别是做嵌入式开发时(如XPE和Wi ...

  3. 安徽师大附中%你赛day4T2 演讲解题报告

    演讲 题目背景: 众所周知,\(\mathrm{Zdrcl}\)是一名天天\(\mathrm{AK}\)的高水平选手. 作为一民长者,为了向大家讲述自己\(\mathrm{AK}\)的经验,他决定在一 ...

  4. bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 526  Solved: 2 ...

  5. 异常message:There is no database named cloudera_manager_metastore_canary_test_db_hive_hivemetastore

    NoSuchObjectException(message:There is no database named cloudera_manager_metastore_canary_test_db_h ...

  6. spring和Quartz的定时功能

    一:前沿 最近在做一个定时的功能,就是在一定时间内查询订单,然后告诉用户未付款,已付款等消息通知,而且要做集群的功能,这个集群的功能是指,我部署两套代码,其中一个定时的功能在运行,另外一个就不要运行. ...

  7. 动态规划:DAG-嵌套矩形

    据说DAG是动态规划的基础,想一想还真的是这样的,动态规划的所有状态和转移都可以归约成DAG DAG有两个典型模型,一个是嵌套矩形问题一个是硬币问题,这里仅介绍一个嵌套矩形问题 等二轮复习的时候再补上 ...

  8. 【HDU5785】Interesting [Manacher]

    Interesting Time Limit: 30 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description Input Outp ...

  9. Oracle 脚本记录

    给表创建序列或触发器 create or replace procedure p_createseq(tablename in varchar2,key in varchar2) Authid Cur ...

  10. HDU1142 (Dijkstra+记忆化搜索)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...