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 star1991 at 2009-09-11 10:25:28 on Problem 1088
#include <stdio.h>
#include <stdlib.h>

int max = 0, R, C;

void look(int N[][101],int i, int j, int now);

int main()
{
    int now=1;
    int i,j;
    int N[101][101] = {0};

    scanf("%d %d",&R,&C);
    for(i=0; i<R; i++)
       for(j=0; j<R; j++)
	  scanf("%d", &N[i][j]);
    R--,C--;
    for(i=0; i<=R; i++)
       for(j=0; j<=C; j++)
          look(N,i,j,now);
    printf("%d\n", max);
    return 0;
}

void look(int N[][101], int i, int j, int now)
{
    int flag=1;
    if(i>0 && N[i-1][j]<N[i][j])
       look(N,i-1,j,now+1),flag=0;
    if(j>0 && N[i][j-1] < N[i][j])
       look(N,i,j-1,now+1),flag=0;
    if(i<R && N[i+1][j]<N[i][j])
       look(N,i+1,j,now+1),flag=0;
    if(j<C && N[i][j+1]<N[i][j])
       look(N,i,j+1,now+1),flag=0;
    if(flag&&max < now)
       max = now;
    return;
}

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