HDU 1400 Mondriaan's dream

Source: Internet
Author: User

Hdu_1400

I borrowed the idea of the contour line in the DP plug. I used 1 to indicate that the corresponding position on the contour line is empty, 0 to indicate that the corresponding position has been put on something, and then DP is performed by grid.

If the top grid is 1 when the current grid is recursed, the grid and the last grid must be placed together with a vertical bone card. Otherwise, the above grid will not be filled with the bone card.

If the number of grids on the left is 0, then the number of grids on the left is 0. If the number of grids on the left is 0, the current number of grids can only be empty. If the number is 1, the current grid can be empty, or you can put a horizontal bone card with the grid on the left.

# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Define Maxd 15# Define St 4096 Typedef  Long   Long  Ll;  Int  N, m; ll f [maxd] [maxd] [st];  Void  Solve (){  Int  I, J, K;  For (I = 1 ; I <= N + 1 ; I ++ ) For (J = 1 ; J <= m; j ++ )  For (K = 0 ; K <( 1 <M + 1 ); K ++) f [I] [J] [k] = 0  ; F [  1 ] [ 1 ] [ 0 ] = 1  ; For (I = 1 ; I <= N; I ++ )  For (J = 1 ; J <= m; j ++ )  For (K = 0 ; K <( 1 <M + 1 ); K ++ ){  If (K & 1 <J ){  If (J <m) f [I] [J + 1 ] [K ^ 1 <J] + = F [I] [J] [k];  Else F [I + 1 ] [ 1 ] [K ^ 1 <J] + = F [I] [J] [k];}  Else  { If (K &( 1 <J- 1  )){  If (J <m) f [I] [J + 1 ] [K ^ 1 <J- 1 ] + = F [I] [J] [k];  Else F [I + 1 ] [ 1 ] [K ^ 1 <J- 1 ] + = F [I] [J] [k];}  If (J <m) f [I] [J + 1 ] [K | 1 <J] + = F [I] [J] [k];  Else F [I + 1 ] [ 1 ] [K | 1 <J] + = F [I] [J] [k] ;}} printf (  " % I64d \ n  " , F [n + 1 ] [ 1 ] [ 0  ]);}  Int  Main (){  While (Scanf ( "  % D  " , & N ,& M), n ){  If (N <M) STD: swap (n, m); solve ();}  Return   0  ;} 

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.