Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
SubmitStatusPracticePOJ 1088
Description
Michael Michael
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
24-17-16-125-24-23-…-3-2-1
Input
RC(1 <= R,C <= 100)RCh0<=h<=10000
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
?Download sourceCode.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <cstdio> #include <cstring> #include <iostream> #include <cmath> using namespace std; int p[110][110], mem[110][110]; int dp(int x, int y){ int i, j, k; int ret = 0; if(mem[x][y] != -1) return mem[x][y]; int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}}; for(i = 0; i < 4; i ++){ if(p[x+dir[i][0]][y+dir[i][1]] == -1) continue; if(p[x+dir[i][0]][y+dir[i][1]] < p[x][y]) ret = max (ret, dp(x+dir[i][0], y+dir[i][1])); } return mem[x][y] = ret + 1; } int main(){ int r, c; int i, j, k; int ans, tmp; while(cin >> r >>c){ memset(p, -1, sizeof(p)); memset(mem, -1, sizeof(mem)); ans = 0; for(i = 1; i <= r; i ++) for(j = 1; j <= c; j ++){ mem[i][j] = -1; scanf("%d", &p[i][j]); } for(i = 1; i <= r; i ++) for(j = 1; j <= c; j ++){ tmp = dp(i, j); if(tmp > ans) ans = tmp; } cout << ans << endl; } return 0; } |
code
more code
~~~~