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 ruc_0722317 at 2007-11-03 21:40:29 on Problem 1088 and last updated at 2007-11-03 21:48:48
感觉和那个0MS的人的算法没什么区别啊??
为什么总是超时?
谁能给几组测试数据吗??
反正讨论区的测试数据都是瞬间出答案的,问题在哪里啊??哪位好心的人能帮个忙啊?
#include<iostream>
using namespace std;
int height[102][102];
int length[102][102];
int longest=0,longestnow;
int r,c;
int search(int x,int y)
{
	if(length[x][y]>=longestnow) longestnow=length[x][y];
	if(height[x][y]>height[x+1][y])
	{
		if(length[x+1][y]<=length[x][y])
		{
			length[x+1][y]=length[x][y]+1;
			search(x+1,y);
		}
	}
	if(height[x][y]>height[x-1][y])
	{
		if(length[x-1][y]<=length[x][y])
		{
			length[x-1][y]=length[x][y]+1;
			search(x-1,y);
		}
	}
	if(height[x][y]>height[x][y+1])
	{
		if(length[x][y+1]<=length[x][y])
		{
			length[x][y+1]=length[x][y]+1;
			search(x,y+1);
		}
	}
	if(height[x][y]>height[x][y-1])
	{
		if(length[x][y-1]<=length[x][y])
		{
			length[x][y-1]=length[x][y]+1;
			search(x,y-1);
		}
	}
	return 0;
}

int main()
{
	int i,j,i1,j1;
	cin>>r>>c;
	for(i=0;i<=r;i++) height[i][0]=10001;
	for(i=0;i<=r;i++) height[i][c+1]=10001;
	for(i=0;i<=c;i++) height[0][i]=10001;
	for(i=0;i<=c;i++) height[r+1][i]=10001;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
			cin>>height[i][j];//initialization
	for(i=1;i<=r;i++)
		for(j=c;j>0;j--)
		{
			for(i1=r;i1>0;i1--)
				for(j1=1;j1<=c;j1++)					
				{
					length[i1][j1]=0;
				}
			longestnow=0;
			length[i][j]=1;
			if(longest<height[i][j])
			{
			search(i,j);
			}
			if(longestnow>longest) longest=longestnow;
		}
	cout<<longest;
	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