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 xhp7185 at 2009-03-10 11:11:35 on Problem 1154
#include <iostream>
using namespace std;
int r,c,s=0;
char b[21][21];
int a[30];
int step(int x, int y)
{
	int max = 0;
	a[b[x][y]-65]=0;
	if (a[b[x][y-1]-65]&&y>=1)
	{
		if (max < step(x, y-1))
		{
			max = step(x, y-1);
		}
	}

	if (a[b[x][y+1]-65]&&y<c-1)
	{
		if (max < step(x, y+1))
		{
			max = step(x, y+1);
		}
	}
	if (a[b[x-1][y]-65]&&x>=1)
	{
		if (max < step(x-1, y))
		{
			max = step(x-1, y);
		}
	}
	if (a[b[x+1][y]-65]&&x<r-1)
	{
		if (max < step(x+1, y))
		{
			max = step(x+1, y);
		}
	}
	a[b[x][y]-65]=1;
	return s=max+1;	  
}
int main()
{
    int x,y,q=0; 
	cin>>r>>c;
	memset (a,1,sizeof (a));
    for(x=0;x<r;x++)
       for(y=0;y<c;y++)
	   {
          cin>>b[x][y];
	   }
	step(0,0);
	printf("%d\n",s);
    return 0;
} 

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