Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f ("submultimi1.in");
  7. ofstream g ("submultimi1.out");
  8.  
  9. int n,st[100],k;
  10.  
  11. void init()
  12. {
  13. st[k]=0;
  14. }
  15.  
  16. int succesor()
  17. {
  18. while(st[k]<n)
  19. {
  20. st[k]++;
  21. return 1;
  22. }
  23. return 0;
  24. }
  25.  
  26. int valid()
  27. {
  28. if(k>1)
  29. if(st[k]-st[k-1]==1)
  30. return 0;
  31. if(st[k-1]>=st[k])
  32. return 0;
  33. return 1;
  34. }
  35.  
  36. void tipar()
  37. {
  38. for(int i=1;i<=k;i++)
  39. g<<st[i]<<' ';
  40. g<<endl;
  41. }
  42.  
  43. void bak()
  44. {
  45. int as;
  46. k=1;
  47. init();
  48. while(k>0)
  49. {
  50. while((as=succesor()) && !valid());
  51. if(as)
  52. {
  53. tipar();
  54. k++;
  55. init();
  56. }
  57. else
  58. k--;
  59.  
  60. }
  61.  
  62.  
  63. }
  64.  
  65.  
  66. int main()
  67. {
  68. f>>n;
  69. bak();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement