| 15 | } |
| 16 | |
| 17 | vector<string> genp(int l, int r) { |
| 18 | vector<string> res; |
| 19 | if (l == 0 and r == 1) { |
| 20 | res.push_back(")"); |
| 21 | return res; |
| 22 | } |
| 23 | if (l > 0) { |
| 24 | for (auto str: genp(l-1, r)) { |
| 25 | str.insert(0,1,'('); |
| 26 | res.push_back(str); |
| 27 | } |
| 28 | } |
| 29 | if (r > 0 and r > l) { |
| 30 | for (auto str: genp(l, r-1)) { |
| 31 | str.insert(0,1,')'); |
| 32 | res.push_back(str); |
| 33 | } |
| 34 | } |
| 35 | return res; |
| 36 | } |
| 37 | |
| 38 | // backtracing |
| 39 | /* The idea is intuitive. |
no test coverage detected