Link
蒟蒻の我的代码(#1,#2,#6 WA):
#include <bits/stdc++.h>
using namespace std;
int r,c,a[110][110],ans,mem[110][110],tmp,dx[]={0,1,0,-1,0},dy[]={0,0,-1,0,1};
int dfs(int x,int y)
{
if(mem[x][y])
return mem[x][y];
mem[x][y] = 1;
bool ok = false;
int maxi = -1;
for(int i = 1;i <= 4;i++)
{
int yx = x + dx[i],yy = y + dy[i];
if(1 <= yx && yx <= c && 1 <= yy && yy <= r && a[yx][yy] < a[x][y])
{
ok = true;
maxi = max(1 + dfs(yx,yy),maxi);
}
else
continue;
}
return (ok) ? mem[x][y] = maxi : mem[x][y] = 1;
}
signed main()
{
cin >> r >> c;
for(int i = 1;i <= r;i++)
{
for(int j = 1;j <= c;j++)
cin >> a[i][j];
}
for(int i = 1;i <= r;i++)
{
for(int j = 1;j <= c;j++)
{
ans = max(dfs(i,j),ans);
}
}
cout << ans;
return 0;
}