Codeforces #436 Div2 E
#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的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- [Leetcode] subsets 求数组所有的子集
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- [Leetcode] text justification 文本对齐
Given an array of words and a length L, format the text such that each line has exactly L characters ...
- C&C++——库头文件及其作用
1. 一些头文件的作用::ANSI C.提供断言,assert(表达式):GCC.GTK,GNOME的基础库,提供很多有用的函数,如有数据结构操作函数.使用glib只需要包含:GCC.文件夹操作函数. ...
- transitionEnd和animationEnd的一个临时解决方案
transtionEnd需要添加前缀,并且存在多次触发问题,animationEnd也需要添加前缀,下面是一个临时性解决方案,解决了部分问题,完美方案探索中 (function(){ var body ...
- BZOJ_DAY6???
昨天没睡好啊啊啊,真是要命,睡不着,今天状态爆炸...34题击破. 下一步目标:网络流24题,树链剖分. (洛谷比赛了好开心,希望这次能比以前强吧,嗯)
- 【NOIP 模拟赛】中值滤波 打表找规律
对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> ...
- 一个JavaScript日期格式化扩展函数
我们都知道在Java和PHP语言中,有专门用于格式化日期对象的类和函数,例如Java中的DateFormat等等,通过这些类和函数,我们可以方便的将一个日期对象按照格式的要求输出为字符串,例如对于同一 ...
- poj 2104 (划分树模板)
Description You are working for Macrohard company in data structures department. After failing your ...
- hbase监控实现
目前实现的监控概览
- eclipse读取含有extjs的项目文件时卡死
打开项目的.project文件,将<buildCommand> <name>org.eclipse.wst.jsdt.core.j ...