AcWing 3429. 全排列
原题链接
简单
作者:
糖醋拐杖_8
,
2024-02-25 17:37:56
,
所有人可见
,
阅读 24
#include <cstring>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10;
bool st[N];
int a[N];
int n; string s;
void dfs(int u)
{
if (u > n)
{
for (int i = 1;i <= n;i++)
{
cout << s[a[i] - 1];
}
puts("");
return ;
}
for (int i = 1; i <= n; i ++ )
{
if (!st[i])
{
a[u] = i;
st[i] = true;
dfs(u + 1);
a[u] = 0;
st[i] = false;
}
}
}
int main()
{
cin >> s;
n = s.size();
dfs(1);
return 0;
}