#include<iostream> #include<vector> #include<cstring> #include<cstdio> using namespace std; int a[100][100]; int maxx = 0; void walk(int x, int y, int pos) { if (a[x][y] < a[x + 1][y]) walk(x + 1, y, pos + 1); if (a[x][y] < a[x][y + 1]) walk(x, y + 1, pos + 1); if (a[x][y] < a[x - 1][y]) walk(x - 1, y, pos + 1); if (a[x][y] < a[x][y - 1]) walk(x, y - 1, pos + 1); if (pos > maxx) maxx = pos; return; } int main() { int n, m; while (scanf("%d %d", &n, &m) != EOF) { //a[100][100] = { 0 };不能把a数组都变成0,找了我好久。。还是menset好用 memset(a, 0, sizeof(a)); maxx=0; for (int i = 1;i < n+1;i++) { for (int j = 1;j < m+1;j++) { scanf("%d", &a[i][j]); } } for (int i = 1;i < n+1;i++) { for (int j = 1;j < m+1;j++) { walk(i, j, 0); } } printf("%d\n", maxx); } } |
Double click to view unformatted code.