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

如果中间是盆地,那么这个点应当是1而不是0!!!!

Posted by zhanglanqing at 2016-02-21 14:09:48 on Problem 1088
#include<stdio.h>
#include<iostream>//iostream一定要放在stdio的后面
using namespace std;
int m,n;
//DP记忆化搜索
int dp[1003][1003];
int a[1003][1003];
int dirx[4]={-1,0,1,0};
int diry[4]={0,1,0,-1};

int dfs(int i,int j){
    if(dp[i][j]!=0) return dp[i][j];
    //如果越过了边界,那么是0

    if(i==0||j==0||i==n+1||j==m+1)return dp[i][j]=0;
    int maxer=0;//就是他!!,半个小时没看出来!!
    for(int k=0;k<4;k++){
        if(a[i][j]>a[i+dirx[k]][j+diry[k]]){
            maxer=std::max(dfs(i+dirx[k],j+diry[k]),maxer);
        }
    }

    return dp[i][j]=maxer+1;

}


int main(){
   //freopen("D:\\in.txt","r",stdin);

   scanf("%d%d",&n,&m);
    for(int i=0;i<1003;i++){
        for(int j=0;j<1003;j++){
            a[i][j]=-1;
            dp[i][j]=0;
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&a[i][j]);
        }
    }


    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
          dfs(i,j);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            ans=std::max(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
    
}




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