标签:style blog http java color strong
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
25
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <ctype.h> 8 #include <cmath> 9 #include <algorithm> 10 #define LL long long 11 using namespace std; 12 int rows,cols; 13 int table[101][101],rec[101][101]; 14 int solve(int x,int y,int height){ 15 if(x < 0 || y < 0 || x >= rows || y >= cols || table[x][y] <= height) 16 return 0; 17 if(rec[x][y]) return rec[x][y]; 18 rec[x][y] = max(rec[x][y],solve(x-1,y,table[x][y])); 19 rec[x][y] = max(rec[x][y],solve(x+1,y,table[x][y])); 20 rec[x][y] = max(rec[x][y],solve(x,y+1,table[x][y])); 21 rec[x][y] = max(rec[x][y],solve(x,y-1,table[x][y])); 22 return ++rec[x][y]; 23 } 24 int main(){ 25 int i,j,mx,temp; 26 scanf("%d %d",&rows,&cols); 27 for(i = 0; i < rows; i++){ 28 for(j = 0; j < cols; j++){ 29 scanf("%d",table[i]+j); 30 rec[i][j] = 0; 31 } 32 } 33 for(mx = i = 0; i < rows; i++){ 34 for(j = 0; j < cols; j++){ 35 temp = solve(i,j,INT_MIN); 36 if(temp > mx) mx = temp; 37 } 38 } 39 printf("%d\n",mx); 40 return 0; 41 }
标签:style blog http java color strong
原文地址:http://www.cnblogs.com/crackpotisback/p/3835738.html