fork download
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. ifstream fin("submultimi.in");
  5. ofstream fout("submultimi.out");
  6. int n, stack[101];
  7. void print_solution(int level)
  8. {
  9. for(int i=1; i<=level; i++)
  10. cout<< stack[i]<<" " ;
  11. cout<<endl;
  12. }
  13. void solve(int level)
  14. {
  15. if(level<=n)
  16. {
  17. for(int i = stack[level-1]+1; i<=n; ++i)
  18. {
  19. stack[level]=i;
  20. print_solution(level);
  21. solve(level+1);
  22. }
  23. }
  24. }
  25. int main()
  26. {
  27. n=4;
  28. solve(1);
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
1 
1 2 
1 2 3 
1 2 3 4 
1 2 4 
1 3 
1 3 4 
1 4 
2 
2 3 
2 3 4 
2 4 
3 
3 4 
4