#include<iostream> using namespace std; int str[100][100] = { 0 }; int dfs(int str[100][100],int i,int j) { int a, b, c, d,m,n; a = b = c = d = 0; if (str[i][j] > str[i][j + 1]) a= dfs(str, i, j + 1)+1; if (str[i][j] > str[i][j - 1]) b= dfs(str, i, j - 1)+1; if (str[i][j] > str[i - 1][j]) c= dfs(str, i - 1, j)+1; if (str[i][j] > str[i + 1][j]) d= dfs(str, i + 1, j)+1; m = a > b ? a : b; n = c > d ? c : d; return m > n ? m : n; } int main() { int r, c,length=0,end=0; cin >> r >> c; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> str[i][j]; } } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { length = dfs(str, i, j); if (length > end) end = length; } } cout <<end; return 0; } |
Double click to view unformatted code.