比赛 CSP2022普及组 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 上升点列 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.002 s
代码语言 C++ 内存使用 0.30 MiB
提交时间 2022-10-29 17:45:50
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=500+5;
const int M=100+5;
int n,m;
int f[N][M];
struct sdf{
	int x,y;
}q[N];
bool cmp(sdf a,sdf b){
	if (a.x!=b.x)return a.x<b.x;
	return a.y<b.y;
}
int main(){
	freopen ("csp2022pj_point.in","r",stdin);
	freopen ("csp2022pj_point.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d%d",&q[i].x,&q[i].y);
		f[i][0]=1;
	}
	sort(q+1,q+n+1,cmp);
	for (int i=1;i<=n;i++){
		for (int j=1;j<i;j++){
			if (q[j].y>q[i].y)continue;
			int now=(q[i].y-q[j].y)+(q[i].x-q[j].x-1);
			for (int k=now;k<=m;k++){
				f[i][k]=max(f[i][k],f[j][k-now]+1+now);
			} 
		}
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=m;j++)ans=max(ans,f[i][j]+m-j);
	}
	printf("%d\n",ans);
	return 0;
}