9 条题解
-
0
// https://dashoj.com/p/82 #include <bits/stdc++.h> using namespace std; const int N = 15; int n, cnt = 0; bool nb[N]; vector<int> cl; void out() { for (int i = 0; i < cl.size(); i++) { cout << cl[i] << ' '; } cout << endl; } void dfs(int x, int c) { if (cl.size() == n) { out(); return; } for (int i = 1; i <= n; i++) { if (nb[i]) { nb[i] = false; cl.push_back(i); dfs(i, c + 1); cl.pop_back(); nb[i] = true; } } } int main() { fill(&nb[0], &nb[0] + N, true); cin >> n; for (int i = 1; i <= n; i++) { nb[i] = false; cl.push_back(i); dfs(i, 1); cl.pop_back(); nb[i] = true; } return 0; }
信息
- ID
- 82
- 时间
- 2000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 412
- 已通过
- 162
- 上传者