Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直是WrongAnswer,试了很多数据,没找出问题所在……//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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator