-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10776.cpp
More file actions
52 lines (47 loc) · 677 Bytes
/
10776.cpp
File metadata and controls
52 lines (47 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
vector<bool>use;
vector<char>res;
string str;
int k;
int n;
void clear(){
use.clear();
res.clear();
str = "";
k = 0;
n = 0;
}
void back(int x){
if((int)res.size() == k){
for(auto i : res){
cout<<i;
}
cout<<endl;
return;
}
for(int i = x;i< n;i++){
if(use[i] == false){
use[i] = true;
res.push_back(str[i]);
back(i+1);
use[i] = false;
res.pop_back();
}
while((i+1) < n && str[i] == str[i+1]){
i++;
}
}
}
int main(){
while(cin>>str>>k){
n = str.length();
sort(str.begin(),str.end());
use.resize(n);
for(int i = 0;i<n;i++){
use[i] = false;
}
back(0);
clear();
}
}