AcWing 94. 递归实现排列型枚举
原题链接
简单
作者:
Coinisi.
,
2022-04-02 00:33:51
,
所有人可见
,
阅读 152
#include <cmath>
#include <queue>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
//#define int long long
#define IOS ios::sync_with_stdio(false)
using namespace std;
const int N = 20;
int n, path[N];
bool st[N];
void dfs(int u)
{
IOS;
if(u > n)
{
for(int i = 1; i <= n; i ++) cout << path[i] << ' ';
cout << endl;
}
for(int i = 1; i <= n; i ++)
if(st[i] == false)
{
path[u] = i;
st[i] = true;
dfs(u + 1);
st[i] = false;
}
}
signed main()
{
IOS; cin >> n;
dfs(1);
return 0;
}
别卷了创奇