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;
}

 

版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值