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; }
pain and happy in the cruel world.