fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int n, k, x[100];
  7. bool ok = true;
  8.  
  9. void init(){
  10. for(int i = 1; i <= k; i++){
  11. x[i] = i;
  12. }
  13. }
  14.  
  15. void result(){
  16. for(int i = 1; i <= k; i++){
  17. cout << x[i] << ' ';
  18. }
  19. cout << endl;
  20. }
  21.  
  22. void next_combination(){
  23. int i = k;
  24. while(i > 0 && x[i] == n - k + i){
  25. i--;
  26. }
  27. if(i == 0){
  28. ok = false;
  29. }
  30. else{
  31. x[i]++;
  32. for(int j = i + 1; j <= k; j++){
  33. x[j] = x[j - 1] + 1;
  34. }
  35. }
  36. }
  37.  
  38. int main(){
  39. cin >> n >> k;
  40. init();
  41. while(ok){
  42. result();
  43. next_combination();
  44. }
  45. }
  46.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout