SGU-131 Hardwood Floor (state compression)

Source: Internet
Author: User

The main idea: the I-type bricks with 2 * 1 on the grid of n *m Live 2 * 2 (missing a 1 *) L-type bricks, ask how many Zhong Pu methods

The idea of solving a problem: similar to POJ-2411 Mondriaan's dream
Here, S1 represents the state of the previous row, S2 represents the state of the current row, B1 indicates whether the previous column of the previous row has an effect on the current column, and B2 indicates whether the previous column of the current row has an effect on the current column
A table of state transitions can be obtained

The above excerpt from here to write the link content

#include <cstdio>#include <algorithm>#include <cstring>using namespace STD;#define N#define S (1 <<)Long LongAns[n][n], dp[n][s];intN, M;voidInit () {intTif(N < m)        {t = n;        n = m;    m = t; }memset(DP,0,sizeof(DP)); dp[0][(1<< m)-1] =1;}voidDfsintRintCintS1,intS2,intB1,intB2) {if(c = = m) {if(!b1 &&!b2) {DP[R][S2] + = dp[r-1][S1]; }return; }if(!b1 &&!b2) {DFS (R, C +1, S1 <<1, (S2 <<1) |1,0,0); DFS (R, C +1, S1 <<1, (S2 <<1) |1,1,0); DFS (R, C +1, S1 <<1, (S2 <<1) |1,0,1); }if(!B1) DFS (R, C +1, S1 <<1, (S2 <<1) | B2,1,1);if(!B2) {DFS (R, C +1, (S1 <<1) | (1-B1), (S2 <<1) |1,0,1); DFS (R, C +1, (S1 <<1) | (1-B1), (S2 <<1) |1,1,1); } DFS (r, C +1, (S1 <<1) | (1-B1), (S2 <<1) | B2,0,0);}voidSolve () { for(inti =1; I <= N; i++) DFS (i,0,0,0,0,0);printf("%lld\n", ans[n][m] = ans[m][n] = dp[n][(1<< m)-1]);}intMain () {memset(ANS,-1,sizeof(ans)); while(scanf("%d%d", &n, &m)! = EOF) {if(Ans[n][m]! =-1) {printf("%lld\n", Ans[n][m]);Continue;        } init ();    Solve (); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SGU-131 Hardwood Floor (state compression)

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.