fork(7) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. int main() {
  6. int n, r;
  7. std::cin >> n;
  8. std::cin >> r;
  9.  
  10. std::vector<bool> v(n);
  11. for (int i = 0; i < n; ++i) {
  12. v[i] = (i >= (n - r));
  13. }
  14.  
  15. do {
  16. for (int i = 0; i < n; ++i) {
  17. if (v[i]) {
  18. std::cout << (i+1) << " ";
  19. }
  20. }
  21. std::cout << "\n";
  22. } while (std::next_permutation(v.begin(), v.end()));
  23. }
  24.  
Success #stdin #stdout 0.01s 2860KB
stdin
5 3
stdout
3 4 5 
2 4 5 
2 3 5 
2 3 4 
1 4 5 
1 3 5 
1 3 4 
1 2 5 
1 2 4 
1 2 3