赛克尔だよ @ 2021-09-03 21:27:25
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[105][105],f[105][105];
int main(){
freopen("snow.in","r",stdin);
freopen("snow.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
f[i][j]=1;
}
}
int ans=100;
while(ans--){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j+1]<a[i][j]&&j<m){
f[i][j]=max(f[i][j],f[i][j+1]+1);
}
if(a[i][j-1]<a[i][j]&&j>1){
f[i][j]=max(f[i][j],f[i][j-1]+1);
}
if(a[i-1][j]<a[i][j]&&i>1){
f[i][j]=max(f[i][j],f[i-1][j]+1);
}
if(a[i+1][j]<a[i][j]&&i<n){
f[i][j]=max(f[i][j],f[i+1][j]+1);
}
}
}
}
ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans=max(ans,f[i][j]);
}
}
cout<<ans<<endl;
}
by 褚橙 @ 2021-09-03 22:05:19
因为你f[i][j]借助的是上下左右的结果,会不会有没更新?我也只是瞎说说
by SuperBrain0xb @ 2021-09-04 11:23:45
@赛克尔だよ ,你去掉freopen了吗?
by SuperBrain0xb @ 2021-09-04 11:26:01
请用dfs写,这种写法恐怕不对啊(数据好仁慈啊)