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 |
Re:谁能指点一下吗?(2127)我采用了课本上的标程,居然还WA,哪位大虾给我浇浇火In Reply To:谁能指点一下吗?(2127)我采用了课本上的标程,居然还WA,哪位大虾给我浇浇火 Posted by:hujk2008 at 2004-12-03 22:36:47 #include<iostream> using namespace std; const int MAXN = 508 ; __int64 a[MAXN] , b[MAXN] ; __int64 count[MAXN][MAXN] = { 0 }; char map[MAXN][MAXN] ; int n1 , n2 ; void solve( void ) { int i , j ; for( i = 1; i < MAXN ;i ++ ) count[i][0] = count[0][i] = 0 ; for( i = 1 ; i <= n1 ; i ++ ) for( j = 1; j <= n2 ;j ++ ) { if( a[i] == b[j] ) { count[i][j] = count[i - 1][j - 1] + 1 ; map[i][j] = '\\'; } else if( count[i - 1][j] >= count[i][j - 1] ) { count[i][j] = count[i - 1][j] ; map[i][j] ='|' ; } else { count[i][j] = count[i][ j - 1] ; map[i][j] = '-'; } } return ; } void LST ( int x , int y ) { if( x == 0 || y == 0 ) return ; if( map[x][y] == '\\' ) { LST( x - 1 , y - 1 ); //cout << a[x] <<' ' ; printf("%I64d ",a[x] ) ; } else if( map[x][y] == '|' ) LST( x - 1 , y ) ; else LST( x , y - 1 ) ; return ; } int main( void ) { int i ; //cin >> n1 ; scanf("%d",&n1 ) ; for( i = 1 ;i <= n1 ; i ++ ) // cin >> a[i] ; scanf("%I64d",&a[i] ) ; // cin >> n2 ; scanf("%d",&n2 ) ; for( i = 1 ;i <= n2 ; i ++ ) // cin >> b[i] ; scanf("%I64d",&b[i] ) ; solve() ; // cout << count[n1][n2] << endl ; printf("%d\n",count[n1][n2] ) ; LST( n1 , n2 ); //cout << endl ; printf("\n") ; return 0 ; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator