Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个我的精简代码

Posted by fA1sEr at 2015-02-04 19:53:01 on Problem 1088
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator