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; }?
轉載于:https://www.cnblogs.com/AKCqhzdy/p/10245457.html
總結
以上是生活随笔為你收集整理的bzoj2034: [2009国家集训队]最大收益的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 记录一个AndroidX和Android
 - 下一篇: cdq分治浅谈