#include <iostream>//祖传开头
using namespace std;
int a[105][105],f[105][105],r,c;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int DFS(int x,int y)
{
if (f[x][y] != 0)
return f[x][y];
f[x][y] = 1;
for(int i = 0;i < 4;i++)
{
int nx,ny;
nx = x + dx[i];
ny = y + dy[i];
if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && a[nx][ny] < a[x][y]) \
f[x][y] = max(f[x][y],DFS(nx,ny) + 1);
}
return f[x][y];
}
int main()
{
int i,j,maxn = -1000000000;
cin>>r>>c;
for(i = 1;i <= r;i++)
{
for(j = 1;j <= c;j++)
cin>>a[i][j];
}
for(i = 1;i <= r;i++)
{
for(j = 1;j <= c;j++)
maxn = max(maxn,DFS(i,j));
}
cout << maxn;
return 0;
}
思路:DFS
I AK IOI!
火钳刘明
比赛已结束。