Continue to the status of the compressed DP, and find that you are actually on the road.
# Include <algorithm> # Include <Iostream> # Include <Cstdlib> # Include <Cstring> # Include <Cstdio> # Include <Cmath> # Include <Queue> # Include <Stack> # Include <Map> Using Namespace STD; Const Int Maxn = 100 + 5 ; Const Int Maxm = 10 + 5 ; Int N, m, TOT; Int State [ 170 ], Stanum [ 170 ]; Int In [Maxn]; Bool Flg [maxm]; Void DFS ( Int Cur, Int St, Int Count ){ If (Cur = M) {State [tot] = St; stanum [tot ++] = Count; Return ;} Flg [cur + 1 ] = 0 ; DFS (cur + 1 , St < 1 , Count ); If (Cur < 1 ) {Flg [cur + 1 ] = 1 ; DFS (cur + 1 , St <1 | 1 , Count + 1 );} Else { If (Flg [cur- 1 ] = 0 ) {Flg [cur + 1 ] = 1 ; DFS (cur + 1 , St <1 | 1 , Count + 1 );}}} Void Init () {tot = 0 ; DFS ( 0 , 0 , 0 ); // Cout <tot <Endl; } Inline Int Max ( Int A, Int B ){ Return A <B? B: ;} Void Data_in (){ Int TMP; For ( Int I = 1 ; I <= N; I ++ ){ In [I] =0 ; For ( Int J = 1 ; J <= m; j ++ ) {Scanf ( " % D " ,& TMP); TMP = 1 - TMP; In [I] <= 1 ; In [I] | = TMP ;}}} Int DP [ 2 ] [ 170 ] [ 170 ]; Void DP (){ Int Ans = 0 ; Memset (DP, - 1 , Sizeof (DP )); For ( Int I = 0 ; I <tot; I ++ ){ If ( In [ 1 ] & State [I]) Continue ; DP [ 1 ] [I] [ 0 ] = Stanum [I]; ans = Max (ANS, DP [ 1 ] [I] [ 0 ]);} Int Now = 1 ; For ( Int I = 2 ; I <= N; I ++ ) {Now ^ = 1 ; For ( Int J = 0 ; J <tot; j ++){ If ( In [I] & State [J]) Continue ; Else For ( Int K = 0 ; K <tot; k ++ ){ If (State [J] & (State [k] < 1 )) Continue ; Else If (State [J] & (State [k]> 1 )) Continue ; Else For ( Int P = 0 ; P <tot; P ++ ){ If (State [J] & State [p]) Continue ; Else If (DP [now ^ 1 ] [K] [p] =- 1 ) Continue ; Else {DP [now] [J] [k] = Max (DP [now] [J] [K], DP [now ^ 1 ] [K] [p] + Stanum [J]); ans =Max (ANS, DP [now] [J] [k]) ;}}} printf ( " % D \ n " , ANS );} Int Main (){ While (~ Scanf ( " % D " , & N ,& M) {Init (); data_in (); DP ();} Return 0 ;}
View code