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

时隔大半年,再A此题

Posted by speedcell4 at 2012-02-24 13:04:19 on Problem 1088
#include<iostream>

using namespace std;

const int MAXN = 120;
int n,m,x,y,map[MAXN][MAXN],dp[MAXN][MAXN],go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

#define canGo(x,y) (x>0&&y>0&&n>=x&&m>=y)

int DP(int i,int j)
{
    if(dp[i][j]) return dp[i][j];
    else
    {
        dp[i][j]=1;
        for(int k=0;4-k>0;k++)
        {
            x=i+go[k][0];
            y=j+go[k][1];
            if(canGo(x,y)&&map[x][y]>map[i][j]) dp[i][j]=max(DP(i,j),DP(x,y)+1);
        }
        return dp[i][j];
    }
}
int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        for(int i=1;n-i>=0;i++)
        {
            for(int j=1;m-j>=0;j++)
            {
                dp[i][j]=0;
                scanf("%d",&map[i][j]);
            }
        }
        int ans=-1;
        for(int i=1;n-i>=0;i++)
        {
            for(int j=1;m-j>=0;j++)
            {
                ans=max(ans,DP(i,j));
            }
        }
        printf("%d\n",ans);
    }
}

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