PKU 2411 Mondriaan's dream DP status Compression

Source: Internet
Author: User

 

I have never done any State compression questions before. Today I have seen it. I have read the following brilliant words before .-_-

 

It should have been very early that the question of AC has been adjusted to the present, why? This is why I am in poor state!

 

I read a report in the afternoon. Others used the DFS method. One of them had the same idea as I did, but I didn't have any data. The idea was right at the beginning, the mistake was made under a very small condition. It hurt me. I thought my DP was wrong! It seems that you have to trust your own strength.

 

I think the algorithm is slow and simple. It is no different from the idea of AC in the morning, that is, the binary status of each line.

 

If DP [I] [k] is set to K. Then find out the relationship between it and the state of the I-1 line.

 

Since the I-row DP must fully overwrite the I-1-th row, you only need to grasp this condition and not put it.

 

1. If row I has 0, the row I-1 must be 1;

 

2. If column X in row I is column 1 and row I is 0, the row I must be vertical;

 

3. If column X in row I is 1 and the column in row I-1 is also 1, there is only one possibility, row I is horizontal, therefore, the column x + 1 of row I must also be 1, and because column x + 1 of row I is 1, so the x + 1 column of the I-1 row must also be 1.

 

It is easy to find the link. Oh, I was upset when I thought of it. I should have hated AC for a long time.

 

Oh ~, I almost forgot, there is also the initialization of the second line, initialize it to exist only horizontally or not.

 

This paragraph from: http://gisyhy.blog.163.com/blog/static/129390343200992441558735/

 

PS: the original author's code is beautifully written.

 

 

# Include <stdio. h> <br/> # include <string. h> <br/> # include <stdlib. h> <br/> # include <math. h> <br/> # include <iostream> <br/> # include <string> <br/> # include <vector> <br/> # include <queue> <br /># include <deque> <br/> # include <list> <br/> # include <algorithm> <br/> # include <map> <br/> # include <pash_map> <br/> # include <pash_set> <br/> # include <set> <br/> # include <utility> <br/> using namespace STD; <br/> long DP [11] [1 <11]; <br/> int H, W; <br/> bool isok (int s) <br/>{< br/> int I = 0; <br/> while (I <W) <br/> {<br/> If (S & (1 <I )) <br/> {<br/> if (I = W-1 | (S & (1 <(I + 1) = 0) <br/> return false; <br/> I + = 2; <br/>}< br/> else <br/> I ++; <br/>}< br/> return true; <br/>}< br/> bool isok (INT S1, int S2) <br/>{< br/> int I = 0; <br/> while (I <W) <br/> {<br/> If (S1 & (1 <I )) <br/> {<br/> If (s2 & (1 <I) = 0) <br/> I ++; <br/> else <br/> {<br/> if (I = W-1 | (S1 & (1 <(I + 1 ))) & (s2 & (1 <(I + 1) = 0) <br/> return false; <br/> I + = 2; <br/>}< br/> else <br/> {<br/> If (s2 & (1 <I) = 0) <br/> return false; <br/> I ++; <br/>}< br/> return true; <br/>}< br/> int main () <br/> {<br/> while (scanf ("% d", & H, & W ), H & W) <br/>{< br/> If (H <W) <br/>{< br/> int TMP = W; <br/> W = H; <br/> H = TMP; <br/>}< br/> memset (DP, 0, sizeof (DP )); <br/> int max = (1 <W); <br/> for (INT I = 0; I <Max; ++ I) <br/> If (isok (I) <br/> DP [0] [I] = 1; <br/> for (INT I = 1; I <p; + + I) <br/> for (Int J = 0; j <Max; ++ J) // line I <br/> for (int K = 0; k <Max; ++ K) // line I-1 <br/> If (isok (j, k )) <br/> DP [I] [J] + = DP [I-1] [k]; <br/> printf ("% i64d/N ", DP [h-1] [MAX-1]); <br/>}< br/> return 0; <br/>} 

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.