Algo-Trian

This commit is contained in:
e2hang
2025-09-21 12:21:50 +08:00
parent 24522486f1
commit 3bde00039c
25 changed files with 842 additions and 0 deletions

View File

@@ -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;
}