zoukankan      html  css  js  c++  java
  • 「国家集训队 2009」最大收益

    题目链接

    戳我

    (Solution)

    详细见FQW的论文
    这里写的十分详细,这里就不在说明了,直接上代码吧,毕竟论文的内容十分丰富

    (Code)

    #include<bits/stdc++.h>
    #define int long long 
    #define rg register
    #define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
    using namespace std;
    int read(){
        int x=0,f=1;
    	char c=getchar();
        while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
        return f*x;
    }
    struct node {
    	int l,r,v;
    }a[5010];
    bool cmp1(const node & a , const node & b ){
    	return a.l<b.l;
    }
    bool cmp2(const node & a ,const node & b ){
    	if(a.v==b.v) return a.r<b.r;
    	return a.v>b.v;
    }
    int b[5010],vis[5010];
    bool check(int k,int x){
    	if(b[x]>a[k].r) return 0;
    	if(!vis[x]){vis[x]=k;return 1;}
    	else{
    		if(a[k].r>a[vis[x]].r) return check(k,x+1);
    		else if(check(vis[x],x+1)){vis[x]=k;return 1;}
    		return 0;
    	}
    }
    main(){
    	int n=read(),ans=0;
    	for(int i=1;i<=n;i++)
    		a[i].l=read(),a[i].r=read(),a[i].v=read();
    	sort(a+1,a+1+n,cmp1);
    	for(int i=1;i<=n;i++)
    		b[i]=max(a[i].l,b[i-1]+1);
    	sort(a+1,a+1+n,cmp2);
    	for(int i=1;i<=n;i++){
    		int tot=1;
    		while(b[tot]<a[i].l)
    			tot++;
    		if(check(i,tot))
    			ans+=a[i].v;
    	}
    	printf("%lld
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    Multidimensional Arrays
    TortoiseGit
    Excel教程(14)
    Excel教程(13)
    Excel教程(12)
    Excel教程(11)
    lock
    reflect
    game
    html x
  • 原文地址:https://www.cnblogs.com/hbxblog/p/10287913.html
Copyright © 2011-2022 走看看