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标程

Posted by songhaoran at 2018-05-01 21:32:05 on Problem 1088
#include<iostream>
#include<cstdio>
using namespace std;
int dx[5]={0,-1,0,1,0},               
    dy[5]={0,0,1,0,-1};              
long r,c,i,j,p,t,ans;
long m[101][101],f[101][101];
int search(int,int);    
int main()
{
  cin>>r>>c;
  ans=0;
  for (i=1;i<=r;i++)
   for (j=1;j<=c;j++)
     cin>>m[i][j];        
  for (i=1;i<=r;i++)   
   for (j=1;j<=c;j++)
    {
      t=search(i,j);
      f[i][j]=t;
      if (t>ans) ans=t;    
    }     
  cout<<ans<<endl;  
}
int search(int x,int y) 
{                                
   int i,t,tmp,nx,ny;                
   if (f[x][y]>0)
    { 
       return (f[x][y]);
    } 
   t=1;
   for (i=1;i<=4;i++)
    {
      nx=x+dx[i];
      ny=y+dy[i];
      if ((nx>=1)&&(nx<=r)&&(ny>=1)&&(ny<=c)&&(m[x][y]<m[nx][ny]))
       {
          tmp=search(nx,ny)+1;
          if (tmp>t) t=tmp;                                                                       
       }
    } 
   f[x][y]=t;
   return (t); 
}

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