Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴个我的精简代码#include <iostream> #include <algorithm> using namespace std; const int maxn = 105; int di[] = {-1,0,0,1}; int dj[] = {0,-1,1,0}; int h[maxn][maxn]; int DP[maxn][maxn]; int n, m; int dp(int i, int j) { if (DP[i][j])return DP[i][j]; int k = 0; for (int x = 0; x < 4; x++) { int I = i + di[x], J = j + dj[x]; if (I<0 || I>n-1 || J<0 || J>m-1 || h[i][j]<=h[I][J])continue; k = max(k, dp(I, J)); } return DP[i][j] = k + 1; } int main() { cin >> n >> m; int M = 0; for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)cin >> h[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) M = max(M, dp(i,j)); cout << M << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator