Zoj 1100 Mondriaan's dream

Source: Internet
Author: User

Medium-difficulty DP. The problem of paving bricks involves a combination of mathematical formulas. However, the search + dp method is more ...... Well, it's hard to do.

After studying the bidding process for one afternoon, I finally understood it. Compress the bricks in each layer into binary encoding, and search for whether the state conversion from the previous layer to the current layer can be achieved. Then, from 0 to 11 ...... 11dp.

Void DFS (int n, int from, int to) indicates that there are n bricks from left to right, from indicates the encoding of the First n bricks on this layer, and to indicates the next layer. After modification, 1 indicates filling, and 0 indicates vacancy. The mark was written at 01, and I spent an hour in a daze.

There is nothing else to say. For the current and next layers, there are only three possibilities for putting bricks each time: two horizontal bars, vertical bars, and vertical bars. Horizontal space means two vertical bars cannot be placed ......

 

# Include <cstdio>
# Include <string>

Double B [13] [1, 3000];
Int Tran [20000] [2];

Int H, W, maxmove, ntran;

Void DFS (int n, int from, int)
...{
If (n> W)
Return;
If (n = W)
...{
Tran [ntran] [0] = from;
Tran [ntran ++] [1] =;
Return;
}
DFS (n + 2, (from <2) + 3, (to <2) + 3 );
DFS (n + 1, (from <1) + 1, to <1 );
DFS (n + 1, from <1, (to <1) + 1 );
}

Void dp ()
...{
Memset (B, 0x00, sizeof (B ));
B [0] [(1 <W)-1] = 1;
Int I, J;
For (I = 0; I For (j = 0; j <ntran; j ++)
B [I + 1] [Tran [J] [1] + = B [I] [Tran [J] [0];
}

Int main ()
...{
Freopen ("in.txt", "r", stdin );
While (scanf ("% d", & H, & W ))
...{
If (! H)
Break;
Int T;
If (H <W)
...{
T = H; H = W; W = T;
}
Ntran = 0;
DFS (0, 0, 0 );
// Pt ();
DP ();
// Pb ();
Printf ("%. 0f", B [H] [(1 <W)-1]);
}
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.