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 speedcell4 at 2011-05-08 15:54:45 on Problem 1088
#include<iostream>
using namespace std;
int r,c,max=0,a[101][101]={0},v[101][101]={0};
int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool tothere(int a[101][101],int r,int c,int sx,int sy,int ex,int ey)
{
    if(sx>=0&&sy>=0&&ex>=0&&sy>=0)
    {
        if(sx<r&&sy<c&&ex<r&&ey<c)
        {
            if(a[sx][sy]>a[ex][ey]) return true;
        }
    }
    return false;
}
int findMax2(int a,int b)
{
    if(a>b) return a;
    else return b;
}
int findMax3(int a,int b,int c)
{
    if(a>b) return findMax2(a,c);
    else return findMax2(b,c);
}
int count(int a[101][101],int v[101][101],int r,int c,int x,int y)
{
    if(v[x][y]==-1)
    {
        int pointed=0,way=0;
        for(int i=0;4-i;i++)
        {
            int nx=x+go[i][0];
            int ny=y+go[i][1];
            if(tothere(a,r,c,x,y,nx,ny))
            {
                way++;
                pointed=findMax2(count(a,v,r,c,nx,ny)+1,pointed);
            }
        }
        if(way==0) v[x][y]=1;
        else v[x][y]=pointed;
    }
    return v[x][y];
}
int main()
{
    cin>>r>>c;
    int max=0;
    for(int i=0;r-i;i++)
    {
        for(int j=0;c-j;j++)
        {
            cin>>a[i][j];
            v[i][j]=-1;
        }
    }
    for(int i=0;r-i;i++)
    {
        for(int j=0;c-j;j++)
        {
            max=findMax2(max,count(a,v,r,c,i,j));
        }
    }
    cout<<max<<endl;
 //   system("pause");
}

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