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

第一道深度搜索 一次AC 贴代码 oms

Posted by Heng_Xing at 2011-07-07 16:49:32 on Problem 1088
#include<stdio.h>
int n,m;
int c[101][101];
int b[101][101];
int dp(int i,int j)
{
	int sum=0;
	int l;
	if(c[i][j]!=0)
		return c[i][j];
	if(i-1>=0&&b[i-1][j]<b[i][j])
	{
		sum=dp(i-1,j);
	}
	if(i+1<n&&b[i+1][j]<b[i][j])
	{
		l=dp(i+1,j);
		if(sum<l)
			sum=l;
	}
	if(j-1>=0&&b[i][j-1]<b[i][j])
	{
		l=dp(i,j-1);
		if(sum<l)
			sum=l;
	}
	if(j+1<m&&b[i][j+1]<b[i][j])
	{
		l=dp(i,j+1);
		if(sum<l)
			sum=l;
	}
	return c[i][j]=sum+1;
}
int main (void)
{
	int i,j;
	int sum=0,s;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&b[i][j]);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		{
			s=dp(i,j);
			if(sum<s)
				sum=s;
		}
	printf("%d\n",sum);
	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