Logiking @ 2021-05-08 19:37:59
#include<iostream>
using namespace std;
int r,c;
int sear[201][201];
int dp[201][201];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
//int ans = 1;
int m;
int sousuo(int x,int y){
if(dp[x][y])return dp[x][y];
/*为什么多了这段代码5和7测试点就WA呢?
if(sear[x][y] == 1){
dp[x][y] = 1;
return dp[x][y];
};
*/
int m1 = 0;
int i;
for(i = 0; i < 4; ++i){
int x1 = x + dx[i];
int y1 = y + dy[i];
if(x1 >= 1 && y1 >= 1 && x1 <= r && y1 <= c && sear[x1][y1] < sear[x][y]){
m1 = max(m1,sousuo(x1,y1));
}
}
m1++;
dp[x][y] = m1;
return dp[x][y];
}
int main(){
cin >> r >> c;
int i,j;
for(i=1; i <= r; ++i){
for(j = 1; j <= c ;++j){
cin >> sear[i][j];
}
}
for(i=1; i <= r; ++i){
for(j = 1; j <= c ;++j){
m = max(m,sousuo(i,j));
}
}
cout << m;
// cout << "-----------" << endl;
// for(i=1; i <= r; ++i){
// for(j = 1; j <= c ;++j)
// cout << dp[i][j] << " ";
// cout << endl;
//}
return 0;
}
by simple_dream @ 2021-05-08 19:41:56
@Logiking 高度可能有 0
by simple_dream @ 2021-05-08 19:43:20
if(sear[x][y] == 0){
dp[x][y] = 1;
return dp[x][y];
};
这样可以过
by Logiking @ 2021-05-08 22:03:13
@W文韬武略W 谢谢!!