不败败寇 @ 2019-08-12 17:11:15
求解
#include<bits/stdc++.h>
using namespace std;
int a[110][110],b[110][110],r,c,ans;
int d[2][4]={{-1,0,0,1},{0,-1,1,0}};
int f(int x,int y){
if(b[x][y])return b[x][y];//做过的就不再做了直接返回值
int m=1;
for(int p=0;p<=3;p++){
int dx=x+d[0][p];
int dy=y+d[1][p];
if(dx>=1&&dx<=r&&dy>=1&&dy<=c&&a[dx][dy]<a[x][y])m=max(m,f(dx,dy));
}
b[x][y]=m;
return b[x][y];
}
int main(){
scanf("%d%d",&r,&c);
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
printf("%d ",b[i][j]);
ans=max(ans,f(i,j));
}
cout<<endl;
}
printf("%d",ans);
return 0;
}
by 不败败寇 @ 2019-08-12 17:27:07
dalao可以自行编译运行下看下结果,求解
by 不败败寇 @ 2019-08-12 17:32:48
ok 做出来了