本人太面,求大佬拯救!
查看原帖
本人太面,求大佬拯救!
186068
我怂了楼主2022/3/12 20:13

过了三组数据,测试数据也过了

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,k,an[10001],num[10001],answer;
struct task{
	int start,end;
};
task ta[10001];
bool operator < (const task a,const task b){
	if(a.start<b.start){
		return true;
	}else if(a.start==b.start&&a.end<b.end){
		return true;
	}else{
		return false;
	}
}
int dp(int tas){
	//cout<<tas<<endl;
	int r=ta[tas].end,r1,tas1=tas;
	if(r==n) return 0;
	while(ta[tas].start<=r){
		if(tas<=k)tas++;
		else return n-r;
	}
	if(an[tas]!=-1){
		return an[tas]-r+ta[tas].start-1;
	} 
	r1=num[ta[tas].start];
	int ans=-1;
	for(int i=tas;i<tas+r1;i++){
		ans=max(ans,dp(i)-r+ta[tas].start-1);
	}
	an[tas1]=ans;
	//system("pause");
	return ans;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(an,-1,sizeof(an));
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		int p,t;
		cin>>p>>t;
		num[p]++;
		ta[i].start=p;
		ta[i].end=p+t-1;
	}
	sort(ta+1,ta+k);
	ta[0].start=0;
	ta[0].end=0;
	answer=dp(0);
	cout<<answer;
	return 0;
}


2022/3/12 20:13
加载中...