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
ACM ICPC 2018 World Finals

poj1088 Time Limit Exceeded

Posted by test_60 at 2011-05-11 22:44:07 on Problem 1088
一直提示这个,谁能给点提示,哪里的问题啊?谢谢了
代码:

#include    <stdio.h>

int findroad(int (*R)[102], int r, int c, int i, int j)
{
	int ret = 1;
	int tmp = 1;
	int max = 0;
	int cu = R[i][j];            //当前元素
	int t = R[i-1][j];           //上面
	int b = R[i+1][j];         //下面
	int l = R[i][j-1];          //左面
	int re = R[i][j+1];       //右面
	if (t < cu && t != 0)
	{
		tmp = findroad(R, r, c, i - 1, j);
		if (tmp > max)
			max = tmp;
	}
	if (b < cu && b != 0)
	{
		tmp = findroad(R, r, c, i + 1, j);
		if (tmp > max)
			max = tmp;
	}
	if (l < cu && l != 0)
	{
		tmp = findroad(R, r, c, i, j - 1);
		if (tmp > max)
			max = tmp;
	}
	if (re < cu && re != 0)
	{
		tmp = findroad(R, r, c, i, j + 1);
		if (tmp > max)
			max = tmp;
	}
	ret += max;
	return ret;
}
int main(int argc, char **argv)
{
	int R[102][102] = {0};
	int r, c, i, j;
	int ret;
	int tmp;
	if (!scanf("%d %d", &r, &c))
		return -1;
	for (i = 1; i <= r; i++)
	{
		for (j = 1; j <= c; j++)
		{
			if (!scanf("%d", &R[i][j]))
				return -1;
		}
	}
	ret = 0;
	for (i = 1; i <= r; i++)
	{
		for (j = 1; j <= c; j++)
		{
			tmp = findroad(R, r, c, i, j);
			if (tmp > ret)
				ret = tmp;
		}
	}
	printf("%d\n", ret);
	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