Algo-Trian
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
set<vector<int>> result;
|
||||
|
||||
bool check(const vector<int>& path, int pos) {
|
||||
int row = path.size(); // <20><>ǰҪ<C7B0>ŵ<EFBFBD><C5B5><EFBFBD>
|
||||
for (int i = 0; i < row; i++) {
|
||||
// ͬ<><CDAC> <20><> <20>ڶԽ<DAB6><D4BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (path[i] == pos || abs(path[i] - pos) == row - i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dfs(vector<int>& 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<int> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user