1 条题解
-
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 22, INF = 0x3f3f3f3f, MOD = 1E9 + 7; int n, a[N]; bool st[N]; void dfs(int u) { if (u > n) { for (int i = 1; i <= n; i++) cout << setw(5) << a[i]; cout << endl; return; } for (int i = 1; i <= n; i++) { if (!st[i]) { a[u] = i, st[i] = 1, dfs(u + 1); st[i] = 0; } } } void solve1() { vector<int> a(n); for (int i = 0; i < n; i++) a[i] = i + 1; do { for (auto u : a) cout << setw(5) << u; cout << endl; } while (next_permutation(a.begin(), a.end())); } int main(int argc, char* argv[]) { cin >> n; // solve1(); dfs(1); return 0; }
- 1
信息
- ID
- 517
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 290
- 已通过
- 105
- 上传者