POJ-2965 the pilots brothers 'refrigerator enumeration state Compression

Source: Internet
Author: User

The practice is similar to 1753.

The Code is as follows:

# Include <cstdlib> # include <cstring> # include <cstdio> # include <algorithm> # define start 0 # define end 65535 using namespace STD; char G [6] [6]; int status, CPY, how [20], path [20], times; void pre () {how [1] = 4383, how [2] = 8751, how [3] = 17487, how [4] = 34959, how [5] = 4593; How [6] = 8946, how [7] = 17652, how [8] = 35064, how [9] = 7953, how [10] = 12066; How [11] = 20292, how [12] = 36744, how [13] = 61713, how [14] = 61986; How [15] = 62532, how [16] = 63624; // bit compression storage for the area affected by the reversal of each vertex} bool DFS (INT cur, int POs, int leavings) {If (leavings = 0) {// when the combination is arranged, CPY = status; For (INT I = 0; I <Pos; ++ I) {CPY ^ = How [path [I];} if (CPY = Start) {printf ("% d \ n", times); For (INT I = 0; I <Pos; ++ I) {printf ("% d \ n", (path [I]-1)/4 + 1, (path [I]-1) % 4 + 1 );} return true;} else {return false;} else {for (in T I = cur; I <= 16; ++ I) {path [POS] = I; If (16-pos <leavings) {continue;} If (DFS (I + 1, pos + 1, leavings-1) {return true ;}return false ;}} bool OK (INT times) {If (DFS (1, 0, times )) {return true;} else {return false;} int main () {pre (); // read data for (INT I = 1; I <= 4; ++ I) {scanf ("% s", G [I] + 1); For (Int J = 1; j <= 4; ++ J) {G [I] [J] = G [I] [J] = '-'? 0: 1 ;}for (INT I = 4; I >=1; -- I) {for (Int J = 4; j> = 1; -- J) {status <= 1; if (G [I] [J]) {status | = 1; // compress the entire graph to a 32-bit number.} bool finish = false; while (! Finish) {If (OK (times) {finish = true;} else {++ times ;}} 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.