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 ...
随机推荐
- WordPress 权限方案
每个主机和主机的情况可能有所差异,如下只是概括性地描述,并不一定适用于所有情况.它只适用于进行“常规设置”的情况(注:比如通过“suexec”方式来进行共享主机的,详情见下方) 通常,所有文件是由您的 ...
- nagios+logstash实时监控java日志(一)
https://blog.csdn.net/yanggd1987/article/details/64121459
- D. Babaei and Birthday Cake---cf629D(最长上升子序列和+线段树优化)
http://codeforces.com/problemset/problem/629/D 题目大意: 我第一反应就是求最长上升子序列和 但是数值太大了 不能直接dp求 可以用线段树优化一下 ...
- google 上网
https://chrome.google.com/webstore/detail/%E5%BC%80%E7%9C%BC/kpamljbkjaaljbcgobdealnpalcgicna?hl=zh- ...
- javascript实现 京东淘宝等商城的商品图片大图预览功能(图片放大器)
在京东和淘宝等购买东西的时候,我们会经常预览左侧商品展示图片,把鼠标放到原图,右侧就会有个大图显示出细节.本文将带领大家写一个这样简单的功能! 一.实现原理 当鼠标移入某一图片内部时,图片上部会出 ...
- ArcGIS Engine中的Symbols详解
转自原文ArcGIS Engine中的Symbols详解 本文由本人翻译ESRI官方帮助文档.尊重劳动成果,转载请注明来源. Symbols ArcObjects用了三种类型的Symbol(符号样式) ...
- Meteor第一个应用程序
这一个小教程将教你如何建立你的第一个 Meteor 应用程序. 步骤 1 - 创建App 要创建应用程序,我们将从命令提示符窗口运行 meteor create 命令.该应用程序的名称是 meteor ...
- Django学习系列之request对象
先来一个简单的实例 urls.py from django.conf.urls import url from django.contrib import admin from cmdb import ...
- axis client tomcat jsp调用最少jar
tomcat调用和main方法调用不同在于引入的jar不一样.tomcat引入的jar是全部lib以下的jar包,main是project引入的jar.假设直接进行公布lib下的全部jar都会引入到p ...
- Linux pipe 源代码分析
Linux pipe 源代码分析 管道pipe作为Unix中历史最悠久的IPC机制,存在各个版本号的Unix中,主要用于父子进程之间的通信(使用fork,从而子进程会获得父进程的打开文件表) ...