Viottery @ 2020-07-23 16:31:01
代码如下,感谢!
#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int a[105][105];
int ans[105][105];
int r,c;
int dfs(int row,int list){
if(ans[row][list]!= -1){
return ans[row][list];
}
int now=a[row][list];
int up,down,left,right;
if(row - 1>=1){
if(a[row - 1][list]<now){
up=dfs(row - 1,list);
}
}
if(row + 1<=r){
if(a[row + 1][list]<now){
down=dfs(row + 1,list);
}
}
if(list - 1>= 1){
if(a[row][list - 1]<now){
left=dfs(row,list - 1);
}
}
if(list + 1<=c){
if(a[row][list + 1]<now){
right=dfs(row,list + 1);
}
}
int anss=max(left,right);
anss = max(anss, up);
anss = max(anss, down);
ans[row][list] = anss + 1;
return ans[row][list];
}
int main(){
FAST;
int answer;
cin >> r >> c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin >> a[i][j];
ans[i][j] = -1;
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
answer = max(dfs(i,j),answer);
}
}
cout << answer << endl;
return 0;
}
by Mr_Buck @ 2020-07-30 22:05:58
啊666