fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include<algorithm>
  4. #include<string>
  5. int arr[10];
  6. int r,n;
  7. void dfs(int x,int number)
  8. {
  9. if(x>r)
  10. {
  11. for(int i=1;i<=r;i++)
  12. {
  13. printf("%3d",arr[i]);
  14. }
  15. cout<<endl;
  16. return ;
  17. }
  18. for(int i=number;i<=n;i++)
  19. {
  20. arr[x]=i;
  21. dfs(x+1,i+1);
  22. arr[x]=0;
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30. int main() {
  31. // your code goes here
  32. cin>>n>>r;
  33. dfs(1,1);
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5292KB
stdin
5
3
stdout
  1  2  3
  1  2  4
  1  2  5
  1  3  4
  1  3  5
  1  4  5
  2  3  4
  2  3  5
  2  4  5
  3  4  5