-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise_5-5.cpp
More file actions
35 lines (28 loc) · 821 Bytes
/
exercise_5-5.cpp
File metadata and controls
35 lines (28 loc) · 821 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
// O(2^(m+n))
// 연습문제 5-6 정답은 없음. 겹치지 않아도 2차원 배열 필요.
#include <iostream>
#include <string>
using namespace std;
void generate_interleavings(string& s1, string& s2, string& current, int i, int j) {
if (i == s1.size() && j == s2.size()) {
cout << current << endl;
return;
}
if (i < s1.size()) {
current.push_back(s1[i]);
generate_interleavings(s1, s2, current, i + 1, j);
current.pop_back();
}
if (j < s2.size()) {
current.push_back(s2[j]);
generate_interleavings(s1, s2, current, i, j + 1);
current.pop_back();
}
}
int main() {
string string1 = "ab";
string string2 = "xy";
string current = "";
generate_interleavings(string1, string2, current, 0, 0);
return 0;
}