主题链接:点击打开链接

为了让球队后,删除是合法的。也就是说,对于每一个车辆, 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&#39;t fear, DravDe is kind dp的更多相关文章

  1. codeforces 28D(dp)

    D. Don't fear, DravDe is kind time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  2. [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 ...

  3. Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)

    补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...

  4. CF28D Don't fear, DravDe is kind 背包

    题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...

  5. 【神仙题】【CF28D】 Don't fear, DravDe is kind

    传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先 ...

  6. Codeforces 216D Spider&#39;s Web 树状数组+模拟

    题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, ...

  7. Codeforces 475C Kamal-ol-molk&#39;s Painting 模拟

    主题链接:点击打开链接 意甲冠军:特定n*m矩阵 X代表色 .代表无色 随着x*y形刷子去涂色. 刷子每次能够→或↓移动随意步. 若可以染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: ...

  8. Codeforces 235B Let&#39;s Play Osu! 概率dp(水

    题目链接:点击打开链接 给定n表示有n个格子 以下每一个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include ...

  9. CF28D Don't fear, DravDe is kind

    传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求 ...

随机推荐

  1. IOS设计模式学习(21)享元

    1 前言 在面向对象软件设计中,利用公共对象不仅能节省资源还能提高性能.共享的对象只能提供某些内在的信息,而不能用来识别对象.专门用于设计可共享对象的一种设计模式叫做享元模式(Flyweight pa ...

  2. ovs处理openflow消息的流程

    OVS处理各个openflow消息的详细代码在 ofproto/ofproto.c 中: static enum ofperr handle_openflow__(struct ofconn *ofc ...

  3. [模式识别].(希腊)西奥多里蒂斯&lt;第四版&gt;笔记8它__模板匹配

      在语音识别方面,同样的话都是同一个人,每次说的情况是不同的,难以识别.本章是定义如何适应不同的情况有不同的特性指标. 1,基于最优路径搜索的度量:①贝尔曼最优性原则和动态编程②编辑距离(The E ...

  4. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  5. 设计模式 - Abstract Factory模式(abstract factory pattern) 详细说明

    Abstract Factory模式(abstract factory pattern) 详细说明 本文地址: http://blog.csdn.net/caroline_wendy/article/ ...

  6. Codeforces 484E Sign on Fence(是持久的段树+二分法)

    题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...

  7. Oracle的海量存储技术

    下午去參加一个Oracle有关海量数据存储技术的培训讲座了. 地址在广州市林和西路101号天河区计经大楼西側三楼. 培训发起机构为:广州中睿信息技术有限公司. 以下就简要总结一下所听到的一些东西,也算 ...

  8. RichTextBox 右键显示 ContextMenuTrip

    说明: (1)命名: RichTextBox  -> rtxt1 ContextMenuTrip -> cms1 (2)截图: (3)完整代码: <span style=" ...

  9. 用DOS命令获取文件列表

    其实就是两个命令:dir 跟 tree 在C:盘根目录下生成了一个名为“filelist.txt”的文本文件,该文件中即包含D:盘的文件夹列表. dir d:\ >c:\filelist.txt ...

  10. RH033读书笔记(15)-Lab 16 The Linux Filesystem

    Lab 16 The Linux Filesystem Goal: Develop a better understanding of Linux filesystem essentials incl ...