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

在这里可以过,0MS,其他地方不能过,不知道为什么???

Posted by ssadwlll at 2008-03-22 17:04:39 on Problem 1088
#include <stdio.h>
int snow[1000][1000];
long a[1000][1000];
int x[4]={0,0,1,-1};
int y[4]={1,-1,0,0};
int n,m;
int ok(int i,int j)
{
    return i>=0&&i<=n&&j>=0&&j<=m;
}
long dp(int i,int j)
{
    int k;
    if(a[i][j])
        return a[i][j];
    for(k=0;k<4;k++)
    {
        if(ok(i+x[k],j+y[k]))
            if(snow[i+x[k]][j+y[k]]>snow[i][j])
            {
                if(a[i][j]<dp(i+x[k],j+y[k])+1)
                    a[i][j]=dp(i+x[k],j+y[k])+1;
            }
    }
    return a[i][j];
}
int main()
{
    int i,j;
    long max;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        max=0;
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
                scanf("%d",&snow[i][j]);
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
            {

                 if(max<dp(i,j))
                     max=dp(i,j);
            }
        printf("%ld\n",max+1);
    }
}

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