Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

LIS简单变式

Posted by Frank__Chen at 2019-02-26 21:34:05 on Problem 3616
#include<cstdio>
#include<algorithm>
using namespace std;

struct node{
	int s,e,c;
}a[1005];

bool cmp(node x,node y){
	return x.s<y.s;
}
int n,m,r,res,dp[1005];

int main(){
	scanf("%d%d%d",&n,&m,&r);
	for(int i=1;i<=m;++i)
		scanf("%d%d%d",&a[i].s,&a[i].e,&a[i].c);
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;++i) dp[i]=a[i].c;
	for(int i=2;i<=m;++i){
		for(int j=i-1;j>=1;--j)
			if(a[j].e+r<=a[i].s)
				dp[i]=max(dp[i],dp[j]+a[i].c);
		if(dp[i]>res) res=dp[i];
	}
	printf("%d\n",res);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator