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

又一个帖代码的。这东西很上瘾么

Posted by gaminerie at 2006-08-09 20:38:28 on Problem 1088
In Reply To:不知道这算不算所谓的记忆化搜索。。我的码。 Posted by:11119999 at 2006-08-09 20:38:03
> #include<stdio.h>
> #include<stdlib.h>
> #define MAX 100
> 
> int region[MAX][MAX];
> int dp[MAX][MAX];
> int r;
> int c;
> int Max(int a,int b){
>     if(a>b)return a;
>     else return b;
> }
> int Deep(int i,int j){
>     if(dp[i][j]>0)return dp[i][j];
>     else {
>         dp[i][j]=0;
>         if((i-1)>=0&&region[i][j]>region[i-1][j]){
>             if(dp[i-1][j]>0)dp[i][j]=Max(dp[i][j],dp[i-1][j]+1);
>             else dp[i][j]=Max(dp[i][j],Deep(i-1,j)+1);
>         }
>         if(i+1<r&&region[i][j]>region[i+1][j]){
>             if(dp[i+1][j]>0)dp[i][j]=Max(dp[i][j],dp[i+1][j]+1);
>             else dp[i][j]=Max(dp[i][j],Deep(i+1,j)+1);
>         }
>         if(j-1>=0&&region[i][j]>region[i][j-1]){
>             if(dp[i][j-1]>0)dp[i][j]=Max(dp[i][j],dp[i][j-1]+1);
>             else dp[i][j]=Max(dp[i][j],Deep(i,j-1)+1);
>         }
>         if(j+1<c&&region[i][j]>region[i][j+1]){
>             if(dp[i][j+1]>0)dp[i][j]=Max(dp[i][j],dp[i][j+1]+1);
>             else dp[i][j]=Max(dp[i][j],Deep(i,j+1)+1);
>         }
>     }
>     return dp[i][j];
> }          
>                    
>     
> int main(){
>     int i;
>     int j;
>     int max=-1;
>     
>     scanf("%d %d",&r,&c);
>     for(i=0;i<r;i++)
>         for(j=0;j<c;j++){
>             scanf("%d",&region[i][j]);
>             dp[i][j]=-1;
>         }    
>     for(i=0;i<r;i++)
>         for(j=0;j<c;j++){
>             dp[i][j]=Deep(i,j);
>             if(dp[i][j]>max)max=dp[i][j];
>         }
>     printf("%d\n",max+1);        
>     system("PAUSE");
>     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