Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不知道这算不算所谓的记忆化搜索。。我的码。#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&®ion[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&®ion[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&®ion[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&®ion[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",®ion[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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator