时间复杂度: n!
T(n) = n * T(n - 1) + O(n);
#include <iostream>
using namespace std;
long long ans;
int ok(char str[], int a, int b){
if(b > a){
for(int i = a; i < b; ++i){ // aacc 老师举的列子
if(str[i] == str[b])
return 0;
}
}
return 1;
}
void perm(char str[], int s, int e){
if(s == e){
ans++;
puts(str);
}
else {
for(int i = s; i <= e; ++i){
if(ok(str, s, i)){ //判重
swap(str[s], str[i]);
perm(str, s + 1, e);
swap(str[s], str[i]);
}
}
}
}
int main(){
int n;
ans = 0;
char str[1000];
cin >> n;
getchar();
gets(str);
perm(str, 0, n - 1);
cout << ans << endl;
return 0;
}