HDU 2442 bricks

Source: Internet
Author: User

Hdu_2442

If recursive DP is used, you need to record the state of the two lines of contour lines, and then discuss whether each graph can be embedded into the current state one by one based on the State-by-grid DP.

Because of the write rub, it is time to directly submit the TLE, so we simply pre-process all States first, and then output the correct results every time O (1.

# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Define Maxn 110 # Define Maxm 6 # Define St 4096 Int N, m, d, f [maxn] [maxm] [st], DP [maxn] [maxm];  Void Prepare ( Int N, Int  M ){  Int  I, J, K;  For (I = 0 , D = 1 ; I <m; I ++) d <= 2  ;  For (I = 0 ; I <= N; I ++)  For (J = 0 ; J <m; j ++ )  For (K = 0 ; K <D; k ++) f [I] [J] [k] = 0  ; F [I] [J] [  0 ] = 0  ;  For (I = 0 ; I <n; I ++ ){ For (J = 0 ; J <m; j ++ )  For (K = 0 ; K <D; k ++ ){  Int  St; ST = ~ ( 3 < 2 * J) & K | ( 1 < 2 * J & K) < 1 | 1 < 2 * J;  If (J = m- 1 ) F [I + 1 ] [ 0 ] [St] = STD: max (F [I + 1 ] [ 0  ] [St], F [I] [J] [k]);  Else F [I] [J + 1 ] [St] = STD: max (F [I] [J + 1 ] [St], F [I] [J] [k]);  If (I> = 2 & J <m- 1 & (K> 2 * J & 7 ) = 7  ) {St = K &~ ( 7 < 2 * J); F [I] [J + 1 ] [St] = STD: max (F [I] [J +1 ] [St], F [I] [J] [k] + 4  );}  If (I> = 2 & J> = 1 & J <m- 1 & (K> 2 * J- 1 & 15 ) = 15  ) {St = K &~ (15 < 2 * J- 1  ); F [I] [J + 1 ] [St] = STD: max (F [I] [J + 1 ] [St], F [I] [J] [k] + 5  );}  If (I> = 1 & J> = 1 & J <m- 1 & (K &1 < 2 * J- 1 ) & (K & 1 < 2 * J) & (K & 1 < 2 * J + 2  ) {St = K &~ ( 1 < 2 * J + 1 ) ^1 < 2 * J- 1 ^ 1 < 2 * J ^ 1 < 2 * J + 2  ; F [I] [J + 1 ] [St] = STD: max (F [I] [J + 1 ] [St], F [I] [J] [k] + 4  );} If (I> = 1 & J <m- 2 & (K & 1 < 2 * J) & (K & 1 < 2 * J + 2 ) & (K & 1 < 2 * J + 4  ) {St = K &~ (1 < 2 * J + 1 ) ^ 1 < 2 * J ^ 1 < 2 * J + 2 ^ 1 < 2 * J + 4  ; F [I] [J + 1 ] [St] = STD: max (F [I] [J +1 ] [St], F [I] [J] [k] + 4  );}  If (I> = 2 & J <m- 1 & (K & 1 < 2 * J) & (K & 1 < 2 * J + 1 ) & (K & 1 <2 * J + 3  ) {St = K ^ 1 < 2 * J ^ 1 < 2 * J + 1 ^ 1 < 2 * J + 3  ; F [I] [J + 1 ] [St] = STD: max (F [I] [J + 1 ] [St], F [I] [J] [k] + 4  );}}  For (K = 0 , DP [I] [m- 1 ] = 0 ; K <D; k ++) DP [I] [m- 1 ] = STD: max (DP [I] [m- 1 ], F [I + 1 ] [ 0  ] [K]) ;}}  Int Main () {memset (DP,  0 , Sizeof  (DP ));  For ( Int I = 2 ; I <= 6 ; I ++) Prepare ( 100  , I );  While (Scanf ( "  % D  " , & N, & M) =2  ) {Printf (  "  % D \ n  " , DP [n- 1 ] [M- 1  ]);}  Return   0  ;} 
Related Keywords:

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.