1. 程式人生 > >bzoj2034: [2009國家集訓隊]最大收益

bzoj2034: [2009國家集訓隊]最大收益

本校唯一國家隊爺出的題。。。真流弊

強行卡掉優化構圖

大家一起去%吧

我覺得離散化以後就是一個類似匈牙利的貪心了。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;

struct node{int l,r,d;}a[5100];
bool cmpl(node n1,node n2){return
n1.l<n2.l;} bool cmpd(node n1,node n2){return n1.d>n2.d;} int pos[5100],match[5100]; bool gofind(int k,int x) { if(a[k].r<pos[x])return false; if(match[x]==0) {match[x]=k;return true;} else { if(a[match[x]].r<a[k].r)return gofind(k,x+1); else
if(gofind(match[x],x+1)) {match[x]=k;return true;} return false; } } int main() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].d); sort(a
+1,a+n+1,cmpl); for(int i=1;i<=n;i++)pos[i]=max(pos[i-1]+1,a[i].l); for(int i=1,j=1;i<=n;i++) { while(pos[j]<a[i].l&&j<n)j++; a[i].l=j; } sort(a+1,a+n+1,cmpd); LL ans=0; for(int i=1;i<=n;i++) if(gofind(i,a[i].l))ans+=a[i].d; printf("%lld\n",ans); return 0; }