求助
查看原帖
求助
906525
Skywalker2187楼主2024/3/24 14:23

以下代码为何无法输出:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

#define north first
#define south second

// typedef long long LL;
typedef std::pair<int,int> Route;

const int N=5*1e3+10;

using namespace std;

int n;
Route routes[N];

int f[N];

int main()
{
	#ifndef ONLINE_JUDGE
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	#endif
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",routes[i].north,routes[i].south);
	}

	sort(routes+1,routes+n+1);

	for(int i=1;i<=n;i++)
	{
		f[i]=1;
		for(int j=1;j<i;j++)
		{
			if(routes[i].south>=routes[j].south)
			{
				f[i]=max(f[i],f[j]+1);
			}
		}
	}

	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,f[i]);
	}

	printf("%d\n",ans);

	return 0;
}

https://www.luogu.com.cn/problem/P2782

2024/3/24 14:23
加载中...