题目: 有一副多米诺骨牌,包含28张,每个多米诺骨牌正反面各有一个数字。
在7 * 8的网格中各张牌各摆一张,左边是个格子的典树,右边是格子所属的骨牌序号,要求输出所有可能的骨牌序号。
搜索与回溯,注意往右和下搜索,当搜索到最右侧的时候,跳回最左侧。这样才可以遍历所有的节点。
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 10;
int pic[maxn][maxn];
bool use[30];
int code[maxn][maxn];
int dx[] = {
0, 1}; // 上 左 下 右
int dy[] = {
1, 0};
int cnt = 0;
void printO() {
for(int i = 0; i < 7; i++) {
for(int j = 0; j < 8; j++) {
cout << setw(4) << pic[i][j];
}
cout << endl;
}
cout << endl;
}
void read() {
for(int i