Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
108670 | 廖悦扬 | 全排列问题 | C++ | 通过 | 100 | 154 MS | 256 KB | 484 | 2023-11-04 09:12:55 |
#include <bits/stdc++.h> using namespace std; bool vis[10]; int n, ans; void dfs(string s, int dep) { for (int i=1; i<=n; i++) { if (vis[i]) continue; vis[i] = true; string tmp = s+(char)(i+'0'); dfs(tmp, dep+1); if (dep == n-1) { cout << tmp << endl; ans++; } vis[i] = false; } } int main() { // freopen("permutation.in", "r", stdin); // freopen("permutation.out", "w", stdout); cin >> n; dfs("", 0); cout << ans; return 0; }