fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main() {
  5. const int n = 4;
  6. const int m = 3;
  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 0s 5324KB
stdin
3
stdout
0: BBBRR
1: BBRBR
2: BBRRB
3: BRBBR
4: BRBRB
5: BRRBB
6: RBBBR
7: RBBRB
8: RBRBB
9: RRBBB