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

请教,time为0ms的算法是怎样的

Posted by jingminglang at 2010-06-09 00:54:20 on Problem 1088
我的方法#include "stdio.h"
int a[100][100];
int p[100][100];
int r,c;
int f(int m, int n);
int main()
{
 int i,j,l=0,x=1,y=1;
 scanf("%d%d",&r,&c);
 for(i=0;i<r;i++)
    for(j=0;j<c;j++)
    {
        scanf("%d",a[i]+j);
        p[i][j]=0;
    }
 for(i=0;i<r;i++)
    for(j=0;j<c;j++)
     {
     	if(p[i][j]==0)
     	{
     	  y=f(i,j);
     	  if(x<y)
     	     x=y;
     	}
     }
     printf("%d",x);
 return 0;   
}
int f(int m, int n)
{
	    int max=0;
	    if(p[m][n]>0)
	    	return p[m][n];    
	    if(n+1<c)
	    {
       	   if(a[m][n]<a[m][n+1])
    	    {
    	    	p[m][n+1]=f(m,n+1);
    	    	if(max<p[m][n+1])
    		       max=p[m][n+1];
    	    }

	    }

    	if(n-1>=0)
    	{
    	   if(a[m][n]<a[m][n-1])
    	     {
    	     	p[m][n-1]=f(m,n-1);
    		   if(max<p[m][n-1])
    		     max=p[m][n-1];
    	     }    	    
    	     
    	}

    	{
    	     if(a[m][n]<a[m+1][n])
    	      {
    	      	p[m+1][n]=f(m+1,n);
    		   if(max<p[m+1][n])
    		     max=p[m+1][n];
    	      }
    	
    	}

    	if(m-1>=0)
    	{
    	      if(a[m][n]<a[m-1][n])
    	      {
    	      	p[m-1][n]=f(m-1,n);
    		   if(max<p[m-1][n])
    		     max=p[m-1][n];
    	      }

    	}

      
    return p[m][n]=max+1;
}
虽然ac了但耗时较长

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