Advertisement
a53

PartitiiNumar5

a53
Dec 20th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n , x[21], cnt;
  6.  
  7. void Afisare(int k)
  8. {
  9. for(int i =1 ; i <= k ; i ++)
  10. cout << x[i] << " ";
  11. cout << endl;
  12. }
  13.  
  14. void Back(int k , int S)
  15. {
  16. for(int i = x[k-1] ; i <= n ; i += 2)
  17. {
  18. x[k] = i;
  19. if(S + x[k] <= n)
  20. {
  21. if(S + x[k] == n)
  22. Afisare(k), cnt ++;
  23. else
  24. Back(k + 1 , S + x[k]);
  25. }
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. cin >> n;
  32. x[0] = 2;
  33. Back(1 , 0);
  34. if(cnt == 0)
  35. cout << "imposibil\n";
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement