样例是错的,大佬求助!!!
查看原帖
样例是错的,大佬求助!!!
697359
jennycai13楼主2023/6/5 13:03
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int tt,r,c,f[N][N],a[N][N];
int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
struct T{
	int x,y,w;
}t[N];
bool cmp(T c,T d)
{
	return c.w<d.w;
}
int main()
{
	cin>>r>>c;
	for(int i=1;i<=r;i++)
	{
		for(int j=1;j<=c;j++)
		{
			cin>>a[i][j];
			++tt;
			t[tt].x=i;
			t[tt].y=j;
			t[tt].w=a[i][j];
		}
	}
	sort(t+1,t+tt+1,cmp);
	f[t[1].x][t[1].y]=1;
	int ans=1;
	for(int i=2;i<=tt;i++)
	{
		int x=t[i].x,y=t[i].y;
		f[x][y]=1;
		for(int j=0;j<4;j++)
		{
			int xx=x+dx[j],yy=y+dy[j];
			if(xx>=1 and xx<=r and yy>=1 and yy<=c and a[xx][yy]>t[i].w)
			{
				f[xx][yy]=max(f[xx][yy],f[x][y]+1);
				ans=max(ans,f[xx][yy]);
			}
		}
	}
	cout<<ans;
}
2023/6/5 13:03
加载中...