http://www.lydsy.com/JudgeOnline/problem.php?id=2034 (题目链接)
题意
n个任务,每个任务只需要一个时刻就可以完成,完成后获得${W_i}$的收益,每个任务可以在${[S_i,T_i]}$间的任一时刻完成,求最大收益。
Solution
很详细了→_→
代码
// bzoj2034
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define LL long long
#define inf 1<<30
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;
const int maxn=5010,maxm=25000010;
int s[maxn],w[maxn],head[maxn],p[maxn],n,cnt;
struct edge {int to,next;}e[maxm];
struct data {int s,t,v;}a[maxn];
bool cmp(data a,data b) {
return a.v>b.v;
}
bool match(int i,int x) {
if (x>a[i].t) return 0;
if (!p[x]) {p[x]=i;return 1;}
if (a[p[x]].t<a[i].t) return match(i,x+1);
else if (match(p[x],x+1)) {p[x]=i;return 1;}
return 0;
}
int main() {
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d%d%d",&a[i].s,&a[i].t,&a[i].v);
sort(a+1,a+1+n,cmp);
LL ans=0;
for (int i=1;i<=n;i++) {
if (match(i,a[i].s)) ans+=a[i].v;
}
printf("%lld\n",ans);
return 0;
}