CodeForces 28D Don't fear, DravDe is kind dp
主题链接:点击打开链接
为了让球队后,删除是合法的。也就是说,对于每一个车辆, l+r+c 一样,按l+r+c分类。
然后dp一下。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <map>
using namespace std;
#define ll int
#define N 100005
struct node{
int v,c,l,r;
int num;
}car[N];
ll n;
vector<int>G[N], tmp;
set<int> myset;
set<int> ::iterator p;
map<int,int> mymap;
map<int,int> per;
map<int,int> sig;
int pos[N], endpos;
ll work(ll x){
if(G[x].size()==0)return 0;
mymap.clear();
per.clear();
sig.clear();
mymap[0] = 0;
per[0] = -1;
sig[0] = -1;
int ans = 0;
endpos = -1;
/* cout<<"---x:"<<x<<endl;
for(int i = 0; i < G[x].size(); i++)cout<<G[x][i]<<" ";
puts("---");/**/
for(int i = 0; i < G[x].size(); i++) {
node now = car[G[x][i]];
if(mymap.find(now.l)==mymap.end())
continue;
// cout<<"now: "<<G[x][i]<<endl;
if(mymap.find(now.l+now.c)==mymap.end() || mymap[now.l+now.c]<mymap[now.l]+now.v) {
mymap[now.l+now.c] = mymap[now.l]+now.v;
sig[now.l+now.c] = G[x][i];
per[G[x][i]] = sig[now.l];
}
if(now.r==0 && ans<mymap[now.l+now.c])ans = mymap[now.l+now.c], endpos = G[x][i];
}
return ans;
}
int main(){
ll i,j,u,v;
while(cin>>n){
for(i = 1; i <= n; i++) G[i].clear();
myset.clear();
mymap.clear();
for(i = 1; i <= n; i++)
scanf("%d%d%d%d",&car[i].v,&car[i].c,&car[i].l,&car[i].r), car[i].num = i;
for(i = 1; i <= n; i++) {
myset.insert(car[i].c+car[i].l+car[i].r);
}
i = 1;
for(p = myset.begin(); p!=myset.end(); p++, i++)
mymap[*p] = i, pos[i] = *p;
for(i = 1; i <= n; i++)
G[mymap[car[i].c+car[i].l+car[i].r]].push_back(i);
int ans = 0;
for(i = 1; i <= n; i++) {
int now = work(i);
if(now>ans) {
ans = now;
tmp.clear();
u = endpos;
while(u!=-1) {
tmp.push_back(u);
u = per[u];
}
}
}
cout<<tmp.size()<<endl;
for(i = tmp.size()-1; i>=0; i--)
printf("%d%c",tmp[i],i?' ':'\n');
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
CodeForces 28D Don't fear, DravDe is kind dp的更多相关文章
- codeforces 28D(dp)
D. Don't fear, DravDe is kind time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- [Codeforces 28D] Do not fear,DravDe is kind
Brief Intro: 对于四元组(v,c,l,r),求其子序列中v最大的和,并使其满足: 1.Ci+Li+Ri相同 2.L1=0,Rn=0 3.Li=Sigma(C1...Ci-1) Soluti ...
- Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)
补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...
- CF28D Don't fear, DravDe is kind 背包
题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...
- 【神仙题】【CF28D】 Don't fear, DravDe is kind
传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先 ...
- Codeforces 216D Spider's Web 树状数组+模拟
题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, ...
- Codeforces 475C Kamal-ol-molk's Painting 模拟
主题链接:点击打开链接 意甲冠军:特定n*m矩阵 X代表色 .代表无色 随着x*y形刷子去涂色. 刷子每次能够→或↓移动随意步. 若可以染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: ...
- Codeforces 235B Let's Play Osu! 概率dp(水
题目链接:点击打开链接 给定n表示有n个格子 以下每一个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include ...
- CF28D Don't fear, DravDe is kind
传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求 ...
随机推荐
- Case when 的使用方法
SQL Case when 的使用方法 Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THE ...
- HashMap的遍历和排序
1.HashMap的遍历 package com.sheepmu; import java.util.HashMap; import java.util.Iterator; import java.u ...
- win8/win10/win2012r2 存储池 冗余分析
StorageSpace:a. Simple,相当于RAID0,无冗余,不考虑b. Two-way Mirror,双重镜像,至少2块盘,性能单盘,可以坏一块盘c. Three-way Mirror,三 ...
- MFC调试小技巧
今天看acl源码的时候看到一个函数AllocConsole().百度一下感觉这个函数对于调试非常不错,当然对于MFC里面的调试信息,我都是用TRACE打印自己感兴趣的消息的,而且仅仅有在DEBUG里面 ...
- [LeetCode116]Path Sum
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- Discuz 楼主帖子采集
try { ; i < ; i++) { var html = GetHtmls("http://bbs.fobshanghai.com/viewthread.php?tid=3885 ...
- poj2386 Lake Counting(简单DFS)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- 【转】tomcat 访问软连接文件夹下的网页出现404错误,description The requested resource (/xxx.html) is not available.
在 tomcat/webapps/ROOT/ 下建立一个软连接文件ln -s /home/ubuntu/report report 再到report软连接目录里建立个 report.html通过浏 ...
- Android应用公布的准备——生成渠道包
我们须要使用一个变量标明该app的渠道.通常我们能够在manifest中的application节点下声明.例如以下. <meta-data android:name="CHANNEL ...
- JSTL实现int数据的类型的长度
JSTL否int类型转换string该功能.为了解决增益int数据的类型的长度,闹失踪. 得到String的数据的长度是jstl的fn能够${fn:length(string)},但int做数据? 经 ...