#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. Walk 解题报告

    Walk 题目描述 给定一棵 \(n\) 个节点的树,每条边的长度为 \(1\),同时有一个权值\(w\).定义一条路径的权值为路径上所有边的权值的最大公约数.现在对于任意 \(i \in [1,n] ...

  2. Linux产生背景

    By francis_hao Oct 26,2016 很久很久以前,大概在1965年左右,由贝尔实验室(Bell).麻省理工学院(MIT)及通用电气公司(GE)共同发起了一个叫做Multics的项目, ...

  3. linux启动一个web项目时验证码不能出现的问题的解决

    解决方法: 在tomcatcatalina.sh中搜索cygwin=false,然后在它的上面加上这句话JAVA_OPTS='-Djava.awt.headless=true' 具体参考如下图片: 然 ...

  4. oracle的sql语句训练

    --查询工资最高的人的名字select ename ,sal from emp where sal=(select max(sal) from emp );--求出员工的工资在所有人的平均工资之上的人 ...

  5. Out of memory due to hash maps used in map-side aggregation解决办法

    在运行一个group by的sql时,抛出以下错误信息: Task with the most failures(4): -----Task ID:  task_201411191723_723592 ...

  6. Prepare and Deploy Windows Server 2016 Active Directory Federation Services

    https://docs.microsoft.com/en-us/windows/security/identity-protection/hello-for-business/hello-key-t ...

  7. php模板引擎smarty

    一. smarty的特点 速度:相对于其他模板引擎,速度较快 编译型:在下次访问模板时直接访问编译文件,不再进行模板重新编译 缓存技术:可以将用户最终看到的HTML文件缓存成一个静态HTML 插件技术 ...

  8. 【BZOJ】2442: [Usaco2011 Open]修剪草坪

    [算法]动态规划 [题解] 万物皆动规,每时每刻都要想着DP!特别是这种明显可以序列递推的题目. 一个简单的思路是f[i]表示前i个选择合法方案(第i个可选可不选)的最大效率 f[i]=max(f[i ...

  9. autoKeras Windows 的入门测试

    在测试中分析一下ide的效果,在pycharm中测试的时候老师提示内存溢出,而且跑autoKeras的cnn时确实消耗很大空间.但是同样的电脑,换了vscode进行测试的时候没有问题.我也不知道什么回 ...

  10. 链接加载文件gcc __attribute__ section

    在阅读源代码的过程中,发现一个头文件有引用: /** The address of the first device table entry. */ extern device_t devices[] ...