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 ...
随机推荐
- 无向图生成树计数 基尔霍夫矩阵 SPOJ Highways
基尔霍夫矩阵 https://blog.csdn.net/w4149/article/details/77387045 https://blog.csdn.net/qq_29963431/articl ...
- POJ 1328 Radar Installation【贪心 区间问题】
题目链接: http://poj.org/problem?id=1328 题意: 在x轴上有若干雷达,可以覆盖距离d以内的岛屿. 给定岛屿坐标,问至少需要多少个雷达才能将岛屿全部包含. 分析: 对于每 ...
- 在d盘中创建一个文件夹 在文件夹里创建三个txt文本
import java.io.File; import java.io.IOException; public class FileDemo { public static void main(Str ...
- 基于commons-net实现ftp创建文件夹、上传、下载功能
原文:http://www.open-open.com/code/view/1420774470187 package com.demo.ftp; import java.io.FileInputSt ...
- 从头开始学Android之(二)—— Android版本
前面大致的介绍了一下Android的Linux内核层,知道Android是Google在Linux基础上创建的一个应用于移动设备的系统,并在针对移动设备的特殊性,在Linux上做了一些相应的改动建立起 ...
- Ulua_toLua_基本案例(一)
Ulua_toLua_基本案例 在Untiy中用Lua.必需要LuaInterface.LuaInterface的介绍请看:点击打开链接 能够先光写Lua,生成.lua的纯文件.再Unity中通过,l ...
- [javase学习笔记]-9.2 单继承与多重继承
这一节我们来看java中的单继承和多重继承. 在java语言中,支持的是单继承,不直接支持多继承,可是对C++中的多继承进行了改良. 那么什么是单继承和多继承呢? 单继承:一个子类仅仅能有一个直接父类 ...
- UI 07 _ 导航视图控制器 与 属性传值
首先, 先创建三个VC. 完毕点击按钮, 进入下一页, 并可以返回. 要先把导航视图控制器创建出来. 在AppDelegate.m 文件里代码例如以下: #import "AppDelega ...
- [转] logback logback.xml常用配置详解(一)<configuration> and <logger>
转载文章:原文出处:http://aub.iteye.com/blog/1101260 详细整理了logback常用配置, 不是官网手册的翻译版,而是使用总结,旨在更快更透彻的理解其配置 根节点< ...
- C#中,变量前的@符号
看别人写的C#代码,发现有变量前带@,啥意思? string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling& ...