View Code of Problem 17

void kuo(int s[20][20],int y[20][20],int i,int j,int *step,int *max)
{
    int m;
    y[i][j]=1;
    if(s[i][j]<s[i+1][j] || s[i][j]<s[i-1][j] || s[i][j]<s[i][j+1] || s[i][j]<s[i][j-1])
    {
        *step+=1;
        m=*step;
    }
    if(s[i][j]<s[i+1][j])
    {
        *step=m;
        kuo(s,y,i+1,j,&m,max);
        if(*step>*max) *max=*step;
    }
    if(s[i][j]<s[i-1][j])
    {
        *step=m;
        kuo(s,y,i-1,j,&m,max);
        if(*step>*max) *max=*step;
    }
    if(s[i][j]<s[i][j+1])
    {
        *step=m;
        kuo(s,y,i,j+1,&m,max);
        if(*step>*max) *max=*step;
    }
    if(s[i][j]<s[i][j-1])
    {
        *step=m;
        kuo(s,y,i,j-1,&m,max);
        if(*step>*max) *max=*step;
    }
}

int main()
{
    int m,n,i,j,max,step;
    while(~scanf("%d",&n))
    {
        scanf("%d",&m);
        int s[20][20]={0},y[20][20]={0},end=0;
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
                scanf("%d",&s[i][j]);
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
            {
                max=0;
                step=0;
                if(y[i][j]!=1) kuo(s,y,i,j,&step,&max);
                if(max>end) end=max;
            }
        printf("%d\n",end);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 17