Wooph

partitiinumar1

Mar 17th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in ("partitiinumar1.in");
  7. ofstream out ("partitiinumar1.out");
  8.  
  9. int n, st[50], s;
  10.  
  11. void afisare (int k)
  12. {
  13. for (int i = 1; i <= k; i ++)
  14. out << st[i] <<" ";
  15. out << "\n";
  16. }
  17.  
  18. int verif (int k)
  19. {
  20. s = 0;
  21.  
  22. if (st[k] < st[k - 1])
  23. return 0;
  24. if (st[k]==st[k-1])
  25. return 0;
  26. for (int i = 1; i <= k; i ++)
  27. s = s + st[i];
  28.  
  29. if(s > n)
  30. return 0;
  31.  
  32. return 1;
  33. }
  34.  
  35. void back (int k)
  36. {
  37. if(s == n)
  38. afisare(k - 1);
  39.  
  40. for (int i = 1; i <= n - k + 1; i ++)
  41. {
  42. st [k] = i;
  43. if (verif (k))
  44. back(k + 1);
  45. }
  46. }
  47.  
  48. int main ()
  49. {
  50. in >> n;
  51. back (1);
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment