标签:整数 tar sub class scanf color 长度 mod 记忆
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 74996 | Accepted: 27818 |
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
中文题什么的再也不用操心题目都看不懂了。
。23333
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<cmath> using namespace std; const int M = 105; int n, m; int map[M][M]; int ans[M][M]; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; int dp(int x, int y) { int max = 0; if( ans[x][y]>0 ) return ans[x][y]; for(int i=0; i<4; i++) //四个方向 { int xx = x + dx[i]; int yy = y + dy[i]; if( xx>=1 &&xx<=n &&yy>=1 &&yy<=m ) //边界 { if( map[x][y] > map[xx][yy] ) //从高到低才合法 if ( max < dp( xx, yy ) ) max = dp( xx, yy ); } } return ans[x][y] = max + 1; } int main() { while( scanf( "%d%d", &n, &m ) !=EOF ) { memset( map, 0, sizeof(map) ); memset( ans, 0, sizeof(ans) ); for( int i=1; i<=n; i++ ) for( int j=1; j<=m; j++ ) scanf( "%d", &map[i][j] ); for( int i=1; i<=n; i++ ) for( int j=1; j<=m; j++ ) dp( i, j ); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if( ans[1][1] < ans[i][j] ) ans[1][1] = ans[i][j]; printf("%d\n", ans[1][1]); } return 0; }
标签:整数 tar sub class scanf color 长度 mod 记忆
原文地址:http://www.cnblogs.com/gccbuaa/p/7044173.html