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

搞了半天,又是run time error 又是 memory limited 我深感绝望,谁来帮帮我(附代码)

Posted by ggg at 2004-04-24 02:49:36 on Problem 1088
#include<iostream.h>
long a[101][101];
int leng[101][101];
int n,c;
int len(int,int);
int main()
{
 int i;int j;
	
while(	cin>>n>>c)
{
	for( i=1;i<=n;i++)
		for( j=1;j<=c;j++)
		{
			cin>>a[i][j];
			leng[i][j]=-1;
		}
		for(i=0;i<=c+1;i++)
			a[0][i]=-2;
	for(i=0;i<=c+1;i++)
			a[n+1][i]=-2;
	for(j=0;j<=n+1;j++)
		a[j][0]=-2;
for(j=0;j<=n+1;j++)
		a[j][n+1]=-2;

		int max=-1;
		for(int u=1;u<=n;u++)
			for(int v=1;v<=c;v++)
			{
				if(leng[u][v]!=-1)
				{
				if(leng[u][v]>max)
					max=leng[u][v];
				}
				else 
				{
					if(len(u,v)>max)
						max=leng[u][v];
				}
			}
			cout<<max<<endl;
}
			return 0;
}

int len(int u,int v)
{

 
	if(leng[u][v]!=-1)
		return leng[u][v];
	int m=1;
	if(a[u][v]>=a[u-1][v]&&a[u-1][v]!=-2&&len(u-1,v)+1>m)
	{
m=1+leng[u-1][v];
	}
	if(a[u][v]>=a[u+1][v]&&a[u+1][v]!=-2&&len(u+1,v)+1>m)
	{
m=1+leng[u+1][v];
	}
		if(a[u][v]>=a[u][v-1]&&a[u][v-1]!=-2&&len(u,v-1)+1>m)
	{
m=1+leng[u][v-1];
	}

	if(a[u][v]>=a[u][v+1]&&a[u][v+1]!=-2&&len(u,v+1)+1>m)
	{
m=1+leng[u][v+1];
	}
	leng[u][v]=m;
	return m;

    
}

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