GoodLuckCat @ 2024-04-16 13:04:58
WA #1 #3 #5 #7 #8 #9
RE #2 #10
AC #4 #6
#include<iostream>
using namespace std;
int R,C,s,a[101][101],f[101][101],u[4]={0,0,1,-1},v[4]={1,-1,0,0};
int solve(int x,int y)
{
if(x<1||x>R||y<1||y>C)return 0;
if(f[x][y])return f[x][y];
f[x][y]=1;
for(int i=0;i<=3;i++)if(a[x][y]>a[x+u[i]][y+v[i]])f[x][y]=max(f[x][y],solve(x+u[i],y+v[i]));
return f[x][y];
}
int 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++)s=max(s,solve(i,j));
cout<<s;
return 0;
}
by _Andy_Lin_ @ 2024-04-16 14:08:09
#include<iostream>
using namespace std;
int R,C,s,a[102][102],f[102][102],u[4]={0,0,1,-1},v[4]={1,-1,0,0};
int solve(int x,int y)
{
if(x<1||x>R||y<1||y>C)return 0;
if(f[x][y])return f[x][y];
f[x][y]=1;
for(int i=0;i<=3;i++)if(a[x][y]>a[x+u[i]][y+v[i]])f[x][y]=max(f[x][y],solve(x+u[i],y+v[i])+1);
return f[x][y];
}
int 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++)s=max(s,solve(i,j));
cout<<s;
return 0;
}
@GoodLuckCat