llwanan @ 2018-09-30 08:32:48
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#define f(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
inline int re()
{
char c=getchar();int res=0,b=1;
while(c!='-' && ( c<'0' || c>'9' ) ) c=getchar();
if(c=='-') b=-b,c=getchar();
while(c>='0' && c<='9') res=(res<<1)+(res<<3)+c-'0',c=getchar();
return res*b;
}
int chen[103][103],yi[103][103],n,m,ans;
void dfs(int i,int j)
{
if(i<1 || j<1 || i>m || j>n) return ;
if(yi[i+1][j]<yi[i][j]) {if(!chen[i+1][j]) dfs(i+1,j);chen[i][j]=max(chen[i][j],chen[i+1][j]);}
if(yi[i-1][j]<yi[i][j]) {if(!chen[i-1][j]) dfs(i-1,j);chen[i][j]=max(chen[i][j],chen[i-1][j]);}
if(yi[i][j+1]<yi[i][j]) {if(!chen[i][j+1]) dfs(i,j+1);chen[i][j]=max(chen[i][j],chen[i][j+1]);}
if(yi[i][j-1]<yi[i][j]) {if(!chen[i][j-1]) dfs(i,j-1);chen[i][j]=max(chen[i][j],chen[i][j-1]);}
chen[i][j]++; ans=max(ans,chen[i][j]);
}
int main()
{
n=re(),m=re();
f(i,1,m) f(j,1,n) yi[i][j]=re();
f(i,1,m) f(j,1,n) if(!chen[i][j]) dfs(i,j);
f(i,1,m) f(j,1,n) cout<<chen[i][j]<<endl;
cout<<ans;
return 0;
}
by Frostmourne✡凛 @ 2018-09-30 11:21:22
所以说我写了个对拍验证了你的程序,发现。。。。。。QAQ
by Frostmourne✡凛 @ 2018-09-30 11:22:00
你定义的n,m搞反了
by Frostmourne✡凛 @ 2018-09-30 11:24:34
if(i<1 || j<1 || i>m || j>n) return ; 改成if(i<1||j<1||i>n||j>m)return; f(i,1,m) f(j,1,n) yi[i][j]=re(); f(i,1,m) f(j,1,n) if(!chen[i][j]) dfs(i,j); 改成 n=read(),m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) yi[i][j]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(!chen[i][j]) dfs(i,j);
by Frostmourne✡凛 @ 2018-09-30 11:25:27
i是1到n j是1到m 就可以了
by Frostmourne✡凛 @ 2018-09-30 11:25:45
看题目要看清啊
by llwanan @ 2018-09-30 21:02:27
@jianxiake 爱死你了
by llwanan @ 2018-09-30 21:03:09
@jianxiake 向大佬比心
by Frostmourne✡凛 @ 2018-09-30 21:12:45
emmmm.