标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 91574 | Accepted: 34573 |
Description
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
Input
Output
Sample Input
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
Sample Output
25
dp,也可以记忆化搜索
1 //2016.8.5 2 //POJ1088 3 #include<iostream> 4 #include<cstdio> 5 #include<cstring> 6 7 using namespace std; 8 9 int n, m; 10 int h[105][105]; 11 int dp[105][105]; 12 int dx[4] = {0, 1, 0, -1}; 13 int dy[4] = {1, 0, -1, 0}; 14 15 int dfs(int x, int y) 16 { 17 if(dp[x][y])return dp[x][y]; 18 int tmp, maxl = 0; 19 for(int i = 0; i < 4; i++) 20 { 21 int nx = x+dx[i]; 22 int ny = y+dy[i]; 23 if(nx>=0&&nx<n&&ny>=0&&ny<m&&h[nx][ny]<h[x][y]) 24 { 25 tmp = dfs(nx, ny); 26 if(tmp>maxl)maxl = tmp; 27 } 28 } 29 return dp[x][y] = maxl+1; 30 } 31 32 int main() 33 { 34 while(cin>>n>>m) 35 { 36 for(int i = 0; i < n; i++) 37 for(int j = 0; j < m; j++) 38 scanf("%d", &h[i][j]); 39 memset(dp, 0, sizeof(dp)); 40 for(int i = 0; i < n; i++) 41 for(int j = 0; j < m; j++) 42 dfs(i, j);//dp每个点为起点能滑的最大长度 43 int maxlen = 0; 44 for(int i = 0; i < n; i++) 45 for(int j = 0; j < m; j++) 46 if(dp[i][j]>maxlen) 47 maxlen = dp[i][j]; 48 cout<<maxlen<<endl; 49 } 50 51 return 0; 52 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5742806.html