Advertisement
rotti321

submultimi

Mar 2nd, 2022
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define dim 100
  3. using namespace std;
  4.  
  5. ///ifstream f("permutari.in");
  6. ///ofstream g("permutari.out");
  7.  
  8. int sol[dim],n,nr=0,p;
  9.  
  10. void tipar(int k)
  11. {
  12. cout<<"{ ";
  13. for(int i=1;i<=k;i++){
  14. cout<<sol[i]<<" ";
  15. }
  16. cout<<"}"<<endl;
  17. }
  18.  
  19. int valid(int k)
  20. {
  21. for(int i=1;i<=k-1;i++){
  22. if(sol[i]>=sol[k])
  23. return 0;
  24. }
  25. return 1;
  26. }
  27.  
  28. int succesor(int k)
  29. {
  30. if(sol[k]<n){
  31. sol[k]++;
  32. return 1;
  33. }
  34. return 0;
  35. }
  36.  
  37. void citire()
  38. {
  39. cin>>n; ///C(n,p);
  40. }
  41.  
  42. void backtr(int k)
  43. {
  44. if (k>1)
  45. tipar(k-1);
  46. /// else
  47. {
  48. sol[k]=0;
  49. while(succesor(k)){
  50. if(valid(k)){
  51. backtr(k+1);
  52. }
  53. }
  54. }
  55. }
  56. int main()
  57. {
  58. citire();
  59. cout<<"{}"<<endl;
  60. backtr(1);
  61. return 0;
  62. }
Advertisement
RAW Paste Data Copied
Advertisement