HDU 4539 Director Zheng's series of stories

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.