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

一直是WrongAnswer,试了很多数据,没找出问题所在……

Posted by Rojay at 2007-04-18 18:28:50 on Problem 1088
//Wrong Answer的程序
#include<iostream>

using namespace std;

int chang[120][120];
int jiyi[120][120];
int a , b ;

int max( int a1 , int b1 , int c1 , int d1 )
{
	int longest = a1 ;
	if ( b1 > longest ) longest = b1 ;
	if ( c1 > longest ) longest = c1 ;
	if ( d1 > longest ) longest = d1 ;
	return longest ; 
}

int suan ( int x , int y )
{
	if ( jiyi[x][y] != -1 ) return jiyi[x][y];
	if ( x == 0 || y == 0 )
	{	jiyi[x][y] = 0;
		return jiyi[x][y];
	}
	if ( x > a || y > b )
	{	jiyi[x][y] = 0;
		return jiyi[x][y];
	}
	int s1 , s2 , s3 , s4 ;
	if ( chang[x][y] > chang[x-1][y] ) s1 = 1 + suan ( x-1 , y );
	if ( chang[x][y] > chang[x+1][y] ) s2 = 1 + suan ( x+1 , y );
	if ( chang[x][y] > chang[x][y-1] ) s3 = 1 + suan ( x , y-1 );
	if ( chang[x][y] > chang[x][y+1] ) s4 = 1 + suan ( x , y+1 );
	jiyi[x][y] = max ( s1 , s2 , s3 , s4 );
	return jiyi[x][y];
}



int main ( )
{
	while ( cin >> a >> b )
	{
		int aa , bb ;
		for ( aa = 0 ; aa < 120 ; aa++ )
		for ( bb = 0 ; bb < 120 ; bb++ )
		{	jiyi[aa][bb] = -1 ;
			chang[aa][bb] = -1;
		}
	
		int x , y ;
		for ( x = 1 ; x <= a ; x++ )
			for ( y = 1 ; y <= b ; y++ )
				cin >> chang[x][y];
		int out = 0 ;
		for ( x = 1 ; x <= a ; x++ )
			for ( y = 1 ; y <= b ; y++ )
				if ( suan ( x , y ) > out )
					out = jiyi[x][y];
		cout << out << endl;
	}
	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