请问为什么我这份代码搜索得到的第一个结果不是可能结果里面字典序最小的?
#include <bits/stdc++.h>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define remilia int
#define is_my_wife main
using namespace std;
using namespace __gnu_pbds;
int clockk[11];
int affect[11][8] = {
{ 5, 0, 1, 3, 4 },
{ 4, 0, 1, 2 },
{ 5, 1, 2, 4, 5 },
{ 4, 0, 3, 6 },
{ 6, 1, 3, 4, 5, 7 },
{ 4, 2, 5, 8 },
{ 5, 3, 4, 6, 7 },
{ 4, 6, 7, 8 },
{ 5, 4, 5, 7, 8 }
};
vector<int> answer;
int use[11], cnt[11];
int st;
// 去重
bool is[5][5][5][5][5][5][5][5][5];
void iddfs(int step, int cur) {
st = 0;
for (int i = 0; i < 9; i++) {
if (use[i] == 3) {
st++;
}
}
if (st == 9) {
sort(answer.begin(), answer.end());
for (auto & i : answer) {
cout << i << " ";
}
exit(0);
}
// 超过最大步数返回
if (step == cur) {
return;
}
// 按从小到大的操作序号来选择操作
for (int i = 0; i < 9; i++) {
// 每一个操作使用次数不超过四次
if (cnt[i] == 4) {
return;
}
for (int j = 1; j < affect[i][0]; j++) {
use[affect[i][j]] = (use[affect[i][j]] + 1) % 4;
}
if (!is[use[0]][use[1]][use[2]][use[3]][use[4]][use[5]][use[6]][use[7]][use[8]]) {
is[use[0]][use[1]][use[2]][use[3]][use[4]][use[5]][use[6]][use[7]][use[8]] = true;
cnt[i]++;
answer.push_back(i + 1);
iddfs(step, cur + 1);
cnt[i]--;
answer.pop_back();
}
for (int j = 1; j < affect[i][0]; j++) {
use[affect[i][j]] = (use[affect[i][j]] + 3) % 4;
}
}
}
remilia is_my_wife() {
for (register int i = 0; i < 9; i++) {
cin >> clockk[i];
clockk[i] /= 3;
clockk[i]--;
use[i] = clockk[i];
}
for (int i = 0; i >= 0; i++) {
memset(is, 0, sizeof is);
for (int j = 0; j < 9; j++) {
use[j] = clockk[j];
}
iddfs(i, 0);
}
return 0;
}
按理说每次搜索的时候按操作序号从小到大来选择操作, 得到的答案不就是字典序最小的吗, 把vector排了个序就A了, 不是很理解。 还是说这样的思路不太对?