codeforces 28D(dp)
2 seconds
256 megabytes
standard input
standard output
A motorcade of n trucks, driving from city «Z» to city «З», has approached a tunnel, known as Tunnel of Horror. Among truck drivers there were rumours about monster DravDe, who hunts for drivers in that tunnel. Some drivers fear to go first, others - to be the last, but let's consider the general case. Each truck is described with four numbers:
- v — value of the truck, of its passangers and cargo
- c — amount of passanger on the truck, the driver included
- l — total amount of people that should go into the tunnel before this truck, so that the driver can overcome his fear («if the monster appears in front of the motorcade, he'll eat them first»)
- r — total amount of people that should follow this truck, so that the driver can overcome his fear («if the monster appears behind the motorcade, he'll eat them first»).
Since the road is narrow, it's impossible to escape DravDe, if he appears from one side. Moreover, the motorcade can't be rearranged. The order of the trucks can't be changed, but it's possible to take any truck out of the motorcade, and leave it near the tunnel for an indefinite period. You, as the head of the motorcade, should remove some of the trucks so, that the rest of the motorcade can move into the tunnel and the total amount of the left trucks' values is maximal.
The first input line contains integer number n (1 ≤ n ≤ 105) — amount of trucks in the motorcade. The following n lines contain four integers each. Numbers in the i-th line: vi, ci, li, ri (1 ≤ vi ≤ 104, 1 ≤ ci ≤ 105, 0 ≤ li, ri ≤ 105) — describe the i-th truck. The trucks are numbered from 1, counting from the front of the motorcade.
In the first line output number k — amount of trucks that will drive into the tunnel. In the second line output k numbers — indexes of these trucks in ascending order. Don't forget please that you are not allowed to change the order of trucks. If the answer is not unique, output any.
5
1 1 0 3
1 1 1 2
1 1 2 1
1 1 3 0
2 1 3 0
4
1 2 3 5
5
1 1 0 3
10 1 2 1
2 2 1 1
10 1 1 2
3 1 3 0
3
1 3 5
/*
这道题.....雾......
就是按l+r+c分类嘛....
可是...但可是....可但是.....
算了,copycopygiveup.....
*/ #include<bits/stdc++.h> using namespace std;
const int Inf=1e9;
struct truck
{
int v,c,l,id,sum;
truck(int v,int c,int l,int id) : id(id), v(v), c(c), l(l) {}
};
vector<truck> t[];
map<int,pair<int,int> > mp;
vector<int> ans;
int Nxt[];
int n;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int v,c,l,r ;
scanf("%d%d%d%d",&v,&c,&l,&r);
t[c+l+r].push_back(truck(v,c,l,i));
}
int res=;
ans.clear();
for(int s=; s<; s++) //枚举c+l+r的长度
{
if(t[s].size())
{
mp.clear();
int len=t[s].size();
mp[s]=make_pair(,Inf);
for(int i=len-; i>=; i--)
{
int l=t[s][i].l;
int c=t[s][i].c;
int v=t[s][i].v;
int cnt=l+c;
if(mp.find(cnt)==mp.end()) continue;
int val=v+mp[cnt].first; //mp存储dp结果
Nxt[i]=mp[cnt].second;
if(mp[l].first<val)
{
mp[l]=make_pair(val,i); //人数值对应最大价值和当前vector中的编号
}
}
if(res<mp[].first)
{
res=mp[].first;
ans.clear();
for(int i=mp[].second; i<Inf/; i=Nxt[i])
{
ans.push_back(t[s][i].id);
}
}
}
}
printf("%d\n",ans.size());
for(int i=; i<ans.size(); i++)
{
printf("%d",ans[i]);
if(i!=ans.size()-)printf(" ");
}
return ;
}
codeforces 28D(dp)的更多相关文章
- CodeForces 28D Don't fear, DravDe is kind dp
主题链接:点击打开链接 为了让球队后,删除是合法的.也就是说,对于每一个车辆, l+r+c 一样,按l+r+c分类. 然后dp一下. #include <cstdio> #include ...
- Two Melodies CodeForces - 813D (DP,技巧)
https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...
- Consecutive Subsequence CodeForces - 977F(dp)
Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...
- codeforces的dp专题
1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...
- Codeforces 721C [dp][拓扑排序]
/* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG), ...
- CodeForces 607C (DP) Hard problem
题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...
- Codeforces 611d [DP][字符串]
/* 题意:给一个长度不超过5000的字符串,每个字符都是0到9的数字. 要求将整个字符串划分成严格递增的几个数字,并且不允许前导零. 思路: 1.很开心得发现,当我在前i个区间以后再加一个区间的时候 ...
- Codeforces 404D [DP]
/* 我是一个习惯后悔,但是没办法忍受内疚感的二货== 这题是个无脑dp,但是比赛大概20min没出...其实最后5min我好好想想简单化边界条件,可以出的. 题意: 给你一个长度为1e6的由?*01 ...
- Codeforces 119C DP
题意: 有n天,m门课和常数k; 每天上一门课,每门课程有两个属性,最少作业量a,最多作业量b,和难度c. 1<=a<=b<=1e16 c<=100 1<=n<=m ...
随机推荐
- hdu——3861 The King’s Problem
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Java的vector可实现自动增长的数组
Vector维克多提供了向量类(vector)以实现类似动态数组的功能. 首先,在Java中并没有指针这样的概念 ,但如果正确灵活地使用指针又确实可以大大提高程序的质量.比如在c,c++中所谓的“动态 ...
- Spring基于Java的配置
以下内容引用自http://wiki.jikexueyuan.com/project/spring/java-based-configuration.html: 基于Java的配置选项,可以使你在不用 ...
- JavaScript 中 for 循环
在ECMAScript5(简称 ES5)中,有三种 for 循环,分别是: 简单for循环 for-in forEach 在2015年6月份发布的ECMAScript6(简称 ES6)中,新增了一种循 ...
- eclipse设置每次提交代码忽略target、.settings、.svn、.project文件
- [Angular] Refactor Angular Component State Logic into Directives
Allow the base toggle to be a tag (<toggle>) or attribute (<div toggle>). The <toggle ...
- linux 中安装JDK
一般公司差点儿相同全部的server都是搭建在Linux上面的,所以这就免不了.(要是使用Java语言)要在Linux上面布一套JDK也就是Java虚拟机环境. 以下.我详细说一下安装过程,以及可能出 ...
- spring理解一
spring基本工作原理例如以下: 1.查找bean配置文件 2.载入bean配置文件并解析生成中间表示BeanDefinition 3.注冊beanDefinition 4.假设是单例或lazy-i ...
- Visual Studio安装空白 和 VS Code打开失败解决方案
微软博文:https://docs.microsoft.com/zh-cn/visualstudio/install/troubleshooting-installation-issues?view= ...
- XxPay支付系统-boot版本 使用
https://segmentfault.com/a/1190000016987391?utm_source=tag-newest 有三个版本: spring boot 版本: spring clou ...