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

为什么好像没有ls写的那么复杂。。。水过了

Posted by 201030720425 at 2011-05-06 12:30:42 on Problem 1088
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#define N 105
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;
int dp[N][N]={0},ans=0,n,m;
int DP(int a[][N],int i,int j)
{
	int k,f[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
	if(dp[i][j]!=1)
		      return dp[i][j];
	else
	{
				for(k=0;k<4;k++)
				{
					if(j+f[k][1]>=0&&i+f[k][0]>=0&&i+f[k][0]<n&&j+f[k][1]<m&&a[i][j]<a[i+f[k][0]][j+f[k][1]])
					{
						
						dp[i][j]=max(dp[i][j],DP(a,i+f[k][0],j+f[k][1])+1);
					}
				}
				ans=max(ans,dp[i][j]);
		
				return dp[i][j];
				
	}

		
			
}
int main()
{
	int i,j,a[N][N],x,y,min=0x7fffffff;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
		  scanf("%d",&a[i][j]);
		}
		for( i=0;i<n;i++)
			for( j=0;j<m;j++)
			{
				dp[i][j]=1;
			}
		for( i=0;i<n;i++)
			for( j=0;j<m;j++)
			{
				DP(a,i,j);
			}
			if(n==1&&m==1)
			{
				ans=1;
			}
	printf("%d\n",ans);
	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