题解|友好城市
2026-07-24 21:03:04
发布于:广东
4阅读
0回复
0点赞
XP03A的来完成下任务
思路:在x坐标有序时,求y坐标的最大升序子序列长度
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
};
const int N=50010;
int n;
int f[N];
node p[N];
bool cmp(node a,node b){
return a.x<b.x;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>p[i].x>>p[i].y;
sort(p+1,p+n+1,cmp);
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
if(p[j].y<p[i].y)f[i]=max(f[i],f[j]+1);
}
}
int res=0;
for(int i=1;i<=n;i++)res=max(res,f[i]);
cout<<res<<'\n';
}
这里空空如也





有帮助,赞一个