-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
54 lines (42 loc) · 925 Bytes
/
test.cpp
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
53
54
#include<bits/stdc++.h>
using namespace std;
int N, t;
string s;
vector<string> ret;
set<string> st;
void go(int idx, int depth, string target, queue<pair<char, int>> q) {
// cout << "D: " <<depth << ", " << "i: " << idx << "\n";
if (idx == N) {
while(q.size()) {
target += q.front().first;
q.pop();
}
st.insert(target);
return;
}
string tmp = target;
tmp += s[idx];
// 대기하던 것들 pop
while(q.size()) {
if (depth - q.front().second == t) {
target += q.front().first;
tmp += q.front().first;
q.pop();
} else {
break;
}
}
// 지연 X
go(idx + 1, depth + 1, tmp, q);
// 지연
q.push({s[idx], depth});
go(idx + 1, depth + 1, target, q);
}
int main() {
cin >> s >> t;
N = s.size();
queue<pair<char, int>> q;
go(0, 0, "", q);
vector<string> ans(st.begin(), st.end());
for(auto c : ans) cout<<c<<'\n';
}