_S_M_Y_ @ 2024-10-23 14:47:18
#include<bits/stdc++.h>
using namespace std;
long long r,c,a[101][101],i,j,s;
void m(long long ri,long long ci,long long h,long long mx){
if(a[ri+1][ci]<mx){
if(h>s) s=h;
m(ri+1,ci,h+1,a[ri+1][ci]);
}
if(a[ri][ci+1]<mx){
if(h>s) s=h;
m(ri,ci+1,h+1,a[ri][ci+1]);
}
if(a[ri-1][ci]<mx){
if(h>s) s=h;
m(ri-1,ci,h+1,a[ri-1][ci]);
}
if(a[ri][ci-1]<mx){
if(h>s) s=h;
m(ri,ci-1,h+1,a[ri][ci-1]);
}
}
int main(){
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++)
m(i,j,1,a[i][j]);
cout<<s;
return 0;
}
救命
by mx26 @ 2024-10-23 15:12:16
首先,当
1 1\ 0
by mx26 @ 2024-10-23 15:12:35
@s_my
by _S_M_Y_ @ 2024-10-23 15:15:08
谢谢提醒
by mx26 @ 2024-10-23 15:17:39
还有一个问题不知道会不会挂
by mx26 @ 2024-10-23 15:21:49
就是当你ri+1的时候可能访问到101处的数组,有可能会越界
by _S_M_Y_ @ 2024-10-25 15:45:39
好的,谢谢
by _liujunming_ @ 2024-10-25 19:51:46
@s_my
#include<bits/stdc++.h>
using namespace std;
long long ans[205][205];
int n,m;
int s[205][205];
bool no(int a,int b)
{
if(a!=0&&b!=0&&a<=n&&b<=m)return true;
else return false;
}
void dfs(int x,int y,long long score)
{
if(score<=ans[x][y])return ;
else ans[x][y]=score;
if(no(x-1,y)&&s[x-1][y]<s[x][y])dfs(x-1,y,score+1);
if(no(x+1,y)&&s[x+1][y]<s[x][y])dfs(x+1,y,score+1);
if(no(x,y-1)&&s[x][y-1]<s[x][y])dfs(x,y-1,score+1);
if(no(x,y+1)&&s[x][y+1]<s[x][y])dfs(x,y+1,score+1);
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ans[i][j]=-(LONG_LONG_MAX);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&s[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
dfs(i,j,1);
long long maxn=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
maxn=max(maxn,ans[i][j]);
printf("%d",maxn);
return 0;
}
by _S_M_Y_ @ 2024-10-26 09:37:20
@liujunming 谢谢你(· v ·)