The number of DXL-the feeling of the very cute ~

Source: Internet
Author: User

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm>using namespace    std;const int M = 100005;const int N = 16;struct dlx{int d[m], u[m], r[m], l[m], head[5000], s[5000], col[m], row[m];    int ans[5025];    int sz, ANSD;        void init (int tn) {Sz = tn;            for (int i = 0; I <= tn; i + +) {D[i] = u[i] = i; L[i] = i-1;        R[i] = i+1; } l[0] = tn;        R[TN] = 0;        memset (s, 0, sizeof (s));        Memset (Head,-1, sizeof (head));    Head[0] = 0;        } void Insert (int r, int c) {++s[col[++sz] = c];        Row[sz] = r;        D[SZ] = D[c];        U[D[C]] = SZ;        U[SZ] = c;        D[C] = sz;        if (Head[r] < 0) Head[r] = L[sz] = R[sz] = SZ;            else{R[sz] = R[head[r];            L[R[HEAD[R]] = SZ;            L[SZ] = Head[r];        R[HEAD[R]] = SZ; }} void remove (int c) {L[r[c]] = l[c];        R[L[C]] = r[c];  for (int i = d[c]; i = c; i = D[i]) {          for (int j = r[i]; J! = i; j = R[j]) {U[d[j]] = u[j];                D[U[J]] = d[j];            --S[COL[J]]; }}}void resume (int c) {for (int i = u[c]; I! = c; i = U[i]) {for (int j = l[i]; J! = i; j = l[        J]) ++s[col[u[d[j] [d[u[j]]=j]];    } L[r[c]] = r[l[c]] = c;            } bool Dance (int d) {if (r[0] = = 0) {ansd = D;        return true;        } int c = r[0];        for (int i = r[0]; i = 0; i = r[i]) if (S[i] < s[c]) C = i;        Remove (c);            for (int i = d[c]; i = c; i = D[i]) {ans[d] = Row[i];            for (int j = r[i]; J! = i; j = R[j]) {remove (col[j]);            } if (Dance (d+1)) return true;        for (int j = l[i]; J! = i; j = L[j]) resume (col[j]);        } resume (c);    return false;        }} G;char s[17][18];void print () {for (int i = 0; i < G.ANSD; i + +) {G.ans[i]--; int num = g.ans[i]% N; InchT y = g.ans[i]/n%n;        int x = g.ans[i]/n/n;    S[x][y] = num + ' A '; } for (int i = 0; i < N; i + +) printf ("%s\n", S[i]);}    int main () {int f = 1;        while (scanf ("%s", s[0])! = EOF) {if (f) f = 0;        else printf ("\ n");        for (int i = 1; i < N; i + +) scanf ("%s", S[i]);        G.init (1024);                    for (int i = 0; i < N; i + +) {for (int j = 0; J < N; j + +) {for (int o = 0; o < n; o + +) {                        if (s[i][j] = = '-' | | s[i][j] = = ' A ' + O) {G.insert ((i*n+j) *n+o+1, i*n+j+1);                        G.insert ((i*n+j) *n+o+1, n*n+o+i*n+1);                        G.insert ((i*n+j) *n+o+1, n*n*2+o+j*n+1);                    G.insert ((i*n+j) *n+o+1, n*n*3+o+ ((I/4) *4+J/4) *n+1);        }}}} BOOL flag = g.dance (0);    Print (); } return 0;}

  

The number of DXL-the feeling of the very cute ~

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.