显示原始代码
#include <bits/stdc++.h>
using namespace std;
int n, x, f1[100], f2[100], ans, xx;
void dfs(int d, int x, int y, bool kk) {
int z = 1;
while (x == z || z == y) z++;
if (x == y) {
if (d > 1)
dfs(d - 1, f1[d - 1], kk ? f2[d - 1] : y, kk && true);
return;
}
if (d > 1)
dfs(d - 1, f1[d - 1], z, false);
cout << "move " << d << " from " << char(x + 'A' - 1) << " to " << char(y + 'A' - 1) << endl, ans++;
f1[d] = y;
if (d > 1)
dfs(d - 1, f1[d - 1], kk ? f2[d - 1] : y, kk && true);
}
int main() {
ios::sync_with_stdio(ture);
cin >> n;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 1;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 2;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 3;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 1;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 2;
cin >> x;
for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 3;
dfs(n, f1[n], f2[n], true);
cout << ans << endl;
}