【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d913
#include <iostream>
using namespace std;
int a[10][10], guess[10];
bool f(int pos){
if (pos == 7){
for (int i = 1; i <= 6; i++){
int cnt = 0;
for (int j = 1; j <= 6; j++){
if (guess[j] == a[i][j]) cnt++;
}
if (cnt != a[i][0]) return false;
}
return true;
}
for (int i = 1; i <= 6; i++){
bool check = true;
for (int j = 1; j < pos; j++){
if (guess[j] == i){
check = false;
break;
}
}
if (!check) continue;
guess[pos] = i;
if (f(pos+1)) return true;
}
return false;
}
int main() {
for (int i = 1; i <= 6; i++){
for (int j = 1; j <= 6; j++){
cin >> a[i][j];
}
cin >> a[i][0];
}
f(1);
for (int i = 1; i <= 6; i++){
cout << guess[i] << " ";
}
cout << "\n";
}