POJ 2411 Mondriaan's Dream (State compression DP)

Source: Internet
Author: User

Question: Given a matrix, only 1X2 blocks can be placed, and how many different la s can be completely covered by this matrix.

Analysis: If the value is 11 and 01 is vertical, you only need to determine whether the State collection (j | k) of the two adjacent rows is full, whether the two statuses conflict (j & k ).

The first line is directly preprocessed.

 

# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace std; _ int64 dp [12] [1 <11]; // The value is 11 in the horizontal direction and 0 in the vertical direction. // 1 int buff [1 <11]; int n, m; _ int64 ans; bool judge (int B) {bool flag = 1; while (B) {if (B & 1) {if (B> 1) & 1) B = B> 2; else {flag = 0; B = B> 1 ;}} else B = B> 1; if (flag = 0) return 0 ;}return flag ;} void getbuff () {int total = 1 <11; for (int I = 0; I <total; I ++) {if (judge (I )) {buff [I] = 1 ;}}void solve () {int total = 1 <m; for (int I = 1; I <n; I ++) {// the last row must be 1 for (int j = 0; j <total; j ++) {for (int k = 0; k <total; k ++) {if (j | k) = total-1 & buff [(j & k)]) {dp [I] [j] + = dp [I-1] [k] ;}}}ans = dp [n-1] [total-1];} int main () {getbuff (); while (scanf ("% d", & n, & m) {if (n = 0 & m = 0) break; if (n = 1) {if (m % 2 = 0) printf ("1 \ n"); else printf ("0 \ n"); continue ;} int total = 1 <m; memset (dp, 0, sizeof (dp); for (int I = 0; I <total; I ++) {if (buff [I]) dp [0] [I] = 1;} ans = 0; solve (); printf ("% I64d \ n", ans );} return 0 ;}

 

Related Article

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.