fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main() {
  5. const int n = 4;
  6. const int m = n;
  7.  
  8. std::string path(n - 1, 'B');
  9. path.resize(n - 1 + m - 1, 'R'); // path is sorted and would be {B, .., B, R, .., R}
  10.  
  11. int i = 0;
  12. do {
  13. std::cout << i++ << ": "<< path << std::endl; // or any other way t print it
  14. } while (std::next_permutation(path.begin(), path.end()));
  15. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0: BBBRRR
1: BBRBRR
2: BBRRBR
3: BBRRRB
4: BRBBRR
5: BRBRBR
6: BRBRRB
7: BRRBBR
8: BRRBRB
9: BRRRBB
10: RBBBRR
11: RBBRBR
12: RBBRRB
13: RBRBBR
14: RBRBRB
15: RBRRBB
16: RRBBBR
17: RRBBRB
18: RRBRBB
19: RRRBBB