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