向诸位dalao求调
查看原帖
向诸位dalao求调
1196194
JasonWu2015楼主2025/7/28 14:57

8080TLETLE求调

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
ll readll() {
	ll v=1,f=0;
	char c=getchar();
	while(c<48||c>57) v=(c=='-')?-v:v,c=getchar();
	while(c>=48&&c<=57) f=(f<<3)+(f<<1)+(c^48),c=getchar();
	return v*f;
}

ll n,ans=0,dp[1111111];
struct contest { ll x,y; } a[1111111];
bool cmp(contest t1,contest t2) { return t1.y<t2.y; }
int main() {
	n=readll();
	rep(i,1,n) a[i].x=readll(),a[i].y=readll();
	sort(a+1,a+1+n,cmp);
	rep(i,1,n) {
		rep(j,1,i-1)
			if(a[j].y<a[i].x) dp[i]=max(dp[i],dp[j]+1);
		ans=max(ans,dp[i]);
	}
	printf("%d\n",ans);
}
2025/7/28 14:57
加载中...