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 |
空间一维的01背包,内详,转移方程for( int i=1 ; i<=N; i++) { if( a[ i ]>0 ) for( int j=MAX-1 ; j>=a[ i ] ; j--) f[ j ]=max( f[ j ] , f[ j-a[ i ] ]+b[ i ] ); else{ a[ i ]=-a[ i ]; for( int j=0 ; j+a[ i ]<MAX ; j++) f[ j ]=max( f[ j ] , f[ j+a[ i ] ]+b[ i ] ); } } best=max( f[ i ]+i-MID , best ); Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator