The main idea: given a 10*10 triangular chessboard and 12 kinds of parts, each part can only be put once, rotate and flip, some parts have been placed above, to find a solution, so that 12 parts without overlapping on the board
First of all, the subject is DLX, but it's really disgusting. You need to enumerate up to eight positions for each part of each of the parts I started out with all the code, but then I found out that I couldn't do it.
So I chose to hit the table to enter all 12 parts of all 60 orientations, select the first row of the leftmost point as the basis, in order to get each point relative position on the basis points, and then on the map to enumerate the position of the base point, if all points are on the diagram on the line
A total of 60*5*2 's watch played for 40 minutes. The keyboard was knocked out at night and almost the body (C6H12O6) n all consumed 0.0
After this write a little tune on the past ~ also wa a time, forgot the output no solution ...
Code Total 6.8KB table takes up a lot of space but compare Daniel's code to find out that I'm short this year these three questions are really a lot worse than a disgusting
In addition, there are 32288 ways to put this problem. I'm so bored ...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace
Std
int top;
struct ABCD *stack[40000];
struct abcd{ABCD *l,*r,*u,*d;
int x,y,num;
ABCD *bottom;
ABCD (ABCD *l,abcd *r,abcd *u,abcd *d,int x,int y,int Num);
void Del ();
void output ();
void Restore ();
}*HEAD,*HEADS[100];
const int START[]={0,0,4,6,14,15,19,27,31,39,47,48,52,60};
const int size[]={0,3,4,4,4,5,5,5,5,5,5,5,5}; const int table[60][5][2]={{{0,0}, {1,0}, {1,1}, {0,0}, {0,0}}, {{0,0}, {1,-1}, {1,0}, {0,0}, {0,0}}, { {0,0}, {0,1}, {1,0}, {0,0}, {0,0}}, {{0,0}, {0,1}, {1,1}, {0,0}, {0,0}}, {{0,0}, {0,1}, {0,2}, {0,3}, {0,0}}, {{0,0}, {1,0}, {2,0}, {3,0}, {0,0}}, {{0,0}, {0,1}, {0,2}, {1,0}, {0,0}}, {{0,0}, {0,1}, {1,1 }, {2,1}, {0,0}}, {{0,0}, {1,-2}, {1,-1}, {1,0}, {0,0}}, {{0,0}, {1,0}, {2,0}, {2,1}, {0,0}}, {{0,0}, {0,1}, {1,0}, {2,0}, {0,0}}, {{0,0}, {0,1}, {0,2}, {1,2}, {0,0}}, {{0,0}, {1,0}, {2,0}, {2,-1}, {0,0}}, {{0,0}, {1,0}, {1,1}, {1,2}, {0,0},}, {{0,0}, {0,1}, {1,0}, {1,1}, {0,0}}, {{0,0}, {1,0}, {2,0}, {2,1}, {2,2}}, {{0,0}, {0,1}, {0,2}, {1,0}, {2,0}}, {{0}, 0}, {0,1}, {0,2}, {1,2}, {2,2}}, {{0,0}, {1,0}, {2,-2}, {2,-1}, {2,0}}, {{0,0}, {1,-2}, {1,-1}, {1,0}, {1,1}}, {{0,0}, {1,0}, {2,0}, {2,1}, {3,0}}, {{0,0}, {0,1}, {0,2}, {0,3}, {1,1}}, {{0,0}, {1,-1}, {1,0 }, {2,0}, {3,0}}, {{0,0}, {1,0}, {1,1}, {2,0}, {3,0}}, {{0,0}, {0,1}, {0,2}, {0,3}, {1,2}}, {{0,0}, {1
, 0}, {2,-1}, {2,0}, {3,0}}, {{0,0}, {1,-1}, {1,0}, {1,1}, {1,2}}, {0,0}, {0,2}, {1,0}, {1,1}, {1,2}}, {{0,0}, {0,1}, {1,0}, {2,0}, {2,1}}, {{0,0}, {0,1}, {0,2}, {1,0}, {1,2}}, {{0,0}, {0,1}, {1,1}, {2,0} , {2,1}}, {{0,0}, {0,1}, {1,0}, {1,1}, {2,1}}, {{0,0}, {0,1}, {1,-1}, {1,0}, {1,1}}, {{0,0}, {1,0}, {
1,1}, {2,0}, {2,1}}, {{0,0}, {0,1}, {0,2}, {1,0}, {1,1}}, {{0,0}, {0,1}, {0,2}, {1,1}, {1,2}}, {{0,0}, {1,-1}, {1,0}, {2,-1} , {2,0}}, {{0,0}, {0,1}, {1,0}, {1,1}, {1,2}}, {{0,0}, {0,1}, {1,0}, {1,1}, {2,0}}, {{0,0}, {1,-1}, {1,0}, {2,-1}, {3,-1}}, {{0,0}, {0,1}, {0,2}, {1,2}, {1,3}}, {{0,0}, {1,0}, {2,-1}, {2,0}, {3,-1}}, {{0 , 0}, {0,1}, {1,1}, {1,2}, {1,3}}, {{0,0}, {0,1}, {1,-2}, {1,-1}, {1,0}, {0,0}, {1,0}, {2,0}, {2,1}, {3 , 1}, {{0,0}, {0,1}, {0,2}, {1,-1}, {1,0}}, {{0,0}, {1,0}, {1,1}, {2,1}, {3,1}}, {{0,0},} {1,-1}, {1,0 }, {1,1}, {2,0}}, {{0,0}, {1,0}, {1,1}, {2,1}, {2,2}}, {{0,0}, {0,1}, {1,-1}, {1,0}, {2,-1}}, {{0,0} , {0,1}, {1,1}, {1,2}, {2,2}}, {{0,0}, {1,-1}, {1,0}, {2,-2}, {2,-1}, {0,0}, {1,-3}, {1,-2},}, {1,-1}, {1,0}}, {{0,0}, {1,0}, {2,0}, {3,0}, {3,1}}, {{0,0}, {0,1}, {0,2}, {0,3}, {1,0}}, {{0,0}, {0,1}, {1,1} , {2,1}, {3,1}}, {0, 0}, {0,1}, {1,0}, {2,0}, {3,0}}, {{0,0}, {0,1}, {0,2}, {0,3}, {1,3}}, {{0,0}, {1,0}, {2,0}, {3,-1}, {3,
0}}, {{0,0}, {1,0}, {1,1}, {1,2}, {1,3}}};
int map[11][11],repos[11][11],cnt=12;
BOOL Appeared[13],mark[11][11];
void DLX ();
void output ();
void find (int p);
inline char getnum ();
void Del_row (ABCD *pos);
void Add (int p,int pos);
void Del_column (ABCD *pos);
int main () {int i,j;
ABCD *last;
head=new ABCD (0x0,0x0,0x0,0x0,0,0,0);
for (last=head,i=1;i<=67;i++) last=new ABCD (last,0x0,0x0,0x0,0,0,0), heads[i]=last;
for (i=1;i<=10;i++) for (j=1;j<=i;j++) repos[i][j]=++cnt,map[i][j]=getnum ();
for (i=1;i<=12;i++) if (!appeared[i]) for (j=start[i];j!=start[i+1];j++) Add (I,J);
else find (i);
DLX ();
Puts ("No solution");
return 0;
ABCD:: ABCD (ABCD *L,ABCD *r,abcd *u,abcd *d,int x,int y,int Num) {l=l;if (L) l->r=this;
R=r;if (R) r->l=this;
U=u;if (U) u->d=this;
D=d;if (D) d->u=this;
X=x;y=y;num=num;
Bottom=d; if (boTtom) bottom->x++;
void ABCD:: Del () {if (L) l->r=r;
if (R) r->l=l;
if (u) u->d=d;
if (d) d->u=u;
if (bottom) bottom->x--;
Stack[++top]=this;
void ABCD:: Restore () {if (L) l->r=this;
if (R) r->l=this;
if (u) u->d=this;
if (d) d->u=this;
if (bottom) bottom->x++;
void output () {int i,j;
for (i=1;i<=10;i++) {for (j=1;j<=i;j++) Putchar (map[i][j]+ ' A '-1);
Putchar (' \ n ');
} void Del_column (ABCD *pos) {ABCD *temp1,*temp2;
for (Temp1=pos->u;temp1;temp1=temp1->u) {for (temp2=temp1->l;temp2;temp2=temp2->l) Temp2->del ();
for (Temp2=temp1->r;temp2;temp2=temp2->r) Temp2->del ();
Temp1->del ();
} Pos->del ();
} void Del_row (ABCD *pos) {if (!pos) return;
Del_row (POS->R);
Del_column (Pos->bottom);
int x=pos->x,y=pos->y,num=pos->num;
Map[x][y]=num;
} void DLX () {if (!head->r) {output ();
Exit (0);
int bottom=top,minnum=0x7fffffff;
ABCD *temp,*mintemp; for (temp=head->r;temp;temp=temp->r) if (temp->x<minnum) minnum=temp->x,mintemp=temp;
for (Temp=mintemp->u;temp;temp=temp->u) {for (mintemp=temp;mintemp->l;mintemp=mintemp->l);
Del_row (mintemp);
DLX ();
while (Top!=bottom) Stack[top--]->restore ();
} inline char Getnum () {char C; Do C=getchar (); while (c== ' | | c== ' \ n ' | |
c== ' \ R ');
if (c== '. ')
return 0;
appeared[c-' A ' +1]=1;
Return c ' A ' +1;
} void Add (int p,int pos) {int i,j,k,x,y;
for (i=1;i<=10;i++) to (j=1;j<=i;j++) {for (k=0;k<size[p];k++) {x=i+table[pos][k][0];
Y=J+TABLE[POS][K][1];
if (x>0&&y>0&&x<=10&&y<=x);
else break;
} if (K==size[p]) {ABCD *last,*temp;
temp=heads[p];
Last = new ABCD (0x0,0x0,temp->u,temp,0,0,0);
for (k=0;k<size[p];k++) {x=i+table[pos][k][0];
Y=J+TABLE[POS][K][1];
temp=heads[Repos[x][y]];
Last = new ABCD (last,0x0,temp->u,temp,x,y,p); }} void find (int p) {int i,j;
ABCD *last,*temp;
temp=heads[p];
Last = new ABCD (0x0,0x0,temp->u,temp,0,0,0); for (i=1;i<=10;i++) for (j=1;j<=i;j++) if (map[i][j]==p) temp=heads[repos[i][j]],last = new ABCD (last,0x0,te
MP->U,TEMP,I,J,P);
}