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开始可以省不少事,贴个代码,有需要的可以看一下哈

Posted by zhoufenqin at 2012-07-21 00:09:58 on Problem 1088
//只要开始时下表从1开始就可以省不少事

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

int n,m;
int dp[110][110];
int a[110][110];
int dfs(int x,int y)
{
    if(dp[x][y]!=0)
        return dp[x][y];
    int maxn=0;
    if(x==0 || x==n+1 || y==0 || y==m+1)
        return 0;
    if(a[x-1][y]<a[x][y])
        maxn=max(maxn,dfs(x-1,y));
    if(a[x+1][y]<a[x][y])
        maxn=max(maxn,dfs(x+1,y));
    if(a[x][y-1]<a[x][y])
        maxn=max(maxn,dfs(x,y-1));
    if(a[x][y+1]<a[x][y])
        maxn=max(maxn,dfs(x,y+1));
    dp[x][y]=maxn+1;
    return maxn+1;
}
int main()
{

    while(cin>>n>>m)
    {
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                cin>>a[i][j];
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                dfs(i,j);

        int ans=-1;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                if(dp[i][j]>ans)
                    ans=dp[i][j];
        cout<<ans<<endl;
    }

    return 0;
}
/*
3 3
3 2 1
5 6 8
7 4 10

*/

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