#include #include #include using namespace std; set> result; bool check(const vector& path, int pos) { int row = path.size(); // 当前要放的行 for (int i = 0; i < row; i++) { // 同列 或 在对角线上 if (path[i] == pos || abs(path[i] - pos) == row - i) { return false; } } return true; } void dfs(vector& path_, int n){ if(path_.size() == n){ result.emplace(path_); return; } int js = 0; for(int i = 0; i < n; i++) { if(check(path_, i)){ js++; path_.push_back(i); dfs(path_, n); path_.pop_back(); } } } int main(){ int n; cin >> n; vector path; dfs(path, n); auto it = result.begin(); for(int i = 0; i < 3; i++){ for(auto x : *it){ cout << x + 1 << " "; } cout << endl; it++; } cout << result.size() << endl; return 0; }