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

0MS的递归

Posted by poiulkj at 2007-05-18 09:24:29 on Problem 1088
#include<iostream.h>
int r,c,a[101][101],flag[101][101];
int huaxue(int i,int j)
{
	int temp,max=1;
	if(flag[i][j]!=-1) return flag[i][j];
	if(a[i][j]>a[i-1][j]&&i>1)
	{   temp=huaxue(i-1,j);
	    if(max<temp+1) max=temp+1;
	}
	if(a[i][j]>a[i][j-1]&&j>1)
	{   temp=huaxue(i,j-1);
	    if(max<temp+1) max=temp+1;
	}
	if(a[i][j]>a[i+1][j]&&i<r)
	{   temp=huaxue(i+1,j);
	    if(max<temp+1) max=temp+1;
	}
	if(a[i][j]>a[i][j+1]&&j<c)
	{   temp=huaxue(i,j+1);
	    if(max<temp+1) max=temp+1;
	}
	flag[i][j]=max;
	return max;
}

void main()
{
	int i,j,temp,max=0;
	cin>>r>>c;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{cin>>a[i][j];
		 flag[i][j]=-1;
		}
    for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{temp=huaxue(i,j);
            if(max<temp) max=temp;
		}
    cout<<max<<endl;
}

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