#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. BZOJ 1030 文本生成器 | 在AC自动机上跑DP

    题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1030 题解: 鸽 #include<cstdio> #include<al ...

  2. ng依赖注入

    依赖注入 1.注入器在组件的构造函数中写服务constructor(private httpreq:HttpService) { } 2.提供器 providers: [HttpService],

  3. ubuntu环境配置------增加右键菜单打开terminal

    直接安装一个软件包nautilus-open-terminal 终端输入:sudo apt-get install nautilus-open-terminal 重启系统!

  4. 转:安装成功的nginx如何添加未编译安装模块

    原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像a ...

  5. bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居——排序+贪心+set

    Description 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l ...

  6. NYOJ 20 吝啬的国度 (深搜)

    题目链接 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市,他有张该国地图,他想知道如果自己要去参观第T号城市,必须经过的前一个城市是几号 ...

  7. js判断浏览器是否为ie

    使用传统方式 if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Op ...

  8. 智联招聘的python岗位数据结巴分词(一)

    如何获取数据点击这里 下载之后的文件名为:all_results.csv 数据样式大概这样.然后下面我分析的是工作要求  也就是那边的绿框那一列. import csv import os impor ...

  9. win7中下载和安装redis

    下载地址:https://github.com/MicrosoftArchive/redis/releases 这里我下载的是3.2.100版本,下载zip,然后解压.解压后如图所示: 开启redis ...

  10. boost::bind的简单实现

    前言 在上一篇blog中简单的实现了boost::function,支持带有2个参数的函数/函数指针,函数对象,函数适配器/bind类,以及带有1个参数的成员函数指针. 本文接着来介绍如何实现一个简单 ...