Poj 2411 Mondriaan's dream solution report [Dynamic Planning] (Code Part)

Source: Internet
Author: User

# Include <iostream>

# Include <cstdio>

# Include <cstring>

Using namespace STD;

 

Long long DP [12] [3000];

// 0 indicates the upper part of the horizontal or vertical column. 1 indicates the lower part of the vertical column. Each row is a binary number (<2048)

Int main ()

{

Long long H, W, ANS, I, J, K, tmp1, tmp2, L, C, Cs;

Scanf ("% LLD", & CS );

While (Cs --)

{

Scanf ("% LLD", & H, & W );

If (H * W & 1) {printf ("0 \ n"); continue ;}

If (W> H) {tmp1 = H; H = W; W = tmp1;} // H * 2 ^ W, So let W be the smaller one.

Memset (DP, 0, sizeof (DP ));

Tmp1 = W; L = 1; while (tmp1 --) L * = 2;

For (I = 0; I <L; I ++)

{// Obtain the possible conditions of the first line and assign a value of 1

Tmp1 = I; C = W;

While (c)

{

If (tmp1 & 1) tmp1> = 1, C --;

Else if (tmp1 & 3) break;

Else if (C <2) break;

Else tmp1> = 2, c-= 2;

}

If (! C) DP [0] [I] = 1;

}

For (I = 1; I

{// Recursive Addition

For (j = 0; j <L; j ++)

{// Adds the compatibility status of the underlying layer to each status of each row

For (k = 0; k <L; k ++)

{// Search for the status of integration and Increment

Tmp1 = J; tmp2 = K; C = W;

While (c)

{

If (tmp2 & 1)

{

If (tmp1 & 1) break;

Else tmp1> = 1, tmp2> = 1, C --;

}

Else

{

If (tmp1 & 1) tmp1> = 1, tmp2> = 1, C --;

Else if (C <2 | (tmp1 & 3) | (tmp2 & 3) break;

Else tmp1> = 2, tmp2> = 2, c-= 2;

}

}

If (! C) DP [I] [J] + = DP [I-1] [k];

}

If (I = h-1) break; // The top layer must all be 0, and the result is found to be 0.

}

}

Printf ("% LLD \ n", DP [h-1] [0]);

}

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.