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 ytlau9 at 2010-07-02 00:13:43 on Problem 1088
各位大牛給的數據都過了...還是wa..

#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int max(int i, int j){
        if(i>j) return i;
        return j;
}
int max4(int i, int j, int m, int n){
        return max(i,(max(j,max(m,n))));
}
int dp(int b[][110],int a[][110],int i, int j){
        if(b[i][j]>0) return b[i][j];
        int up,down,left,right;
        if(a[i+1][j] < a[i][j] && a[i+1][j]>=0)down = dp(b,a,i+1,j);
        else down = 0;
        if(a[i-1][j] < a[i][j] && a[i-1][j]>=0)up = dp(b,a,i-1,j);
        else up=0;
        if(a[i][j+1] < a[i][j] && a[i][j+1]>=0)right = dp(b,a,i,j+1);
        else right=0;
        if(a[i][j-1] < a[i][j] && a[i][j-1]>=0)left = dp(b,a,i,j-1);
        else left=0;

        b[i][j] = max4(up,down,right,left)+1;
}

void dfs(int b[][110], int a[][110],int r,int c){
        for(int i=1;i<=r;i++)
                for(int j=1;j<=c;j++)
                        if(b[i][j]==0)
                                dp(b,a,i,j);
}

int main(){
        int r,c,ans=1;;
        int a[110][110];
        int dp[110][110];
        scanf("%d %d", &r,&c);
        memset(dp,0,sizeof(dp));

        for(int i=1; i<=r;i++)
                for(int j=1; j<=c;j++)
                        scanf("%d", &a[i][j]);

        for(int i=0; i<=r+1; i++){
                dp[i][0] = a[i][0] = -1;
            dp[i][c+1] = a[i][c+1] = -1;
        }
        for(int i=0;i<=c+1;i++){
                dp[0][i] = a[0][i] = -1;
                dp[r+1][i] = a[r+1][i] = -1;
        }

        dfs(dp,a,r,c);
        for(int i=0;i<=r+1;i++){
                for(int j=0;j<=c+1;j++)
                        if(dp[i][j]>ans) ans = dp[i][j];
        }
        printf("%d\n", ans);
        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