illeas

Untitled

Sep 23rd, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. 2 4 3 1 7 9 4 5
  2. All possible subset a maximum number - a minimum number = all subset result summations
  3.  
  4.  
  5.  
  6. -----------
  7. Tree connecting node sum
  8.  
  9. (n-chieldtree)*chieldtree
  10.  
  11.  
  12.  
  13. -----------
  14. 1 2 7 9 6 8 4 3
  15. All sub array like
  16. 7 9 6
  17. length = 3 *(7+9+6)
  18. #include <bits/stdc++.h>
  19. using namespace std;
  20.  
  21. void allPossibleSubset(int arr[],int n)
  22. {
  23. int count = pow(2,n);
  24. for (int i = 1; i <=count; i++)
  25. {
  26. int total=0;
  27. for (int j = 1; j <=n; j++)
  28. {
  29. int st = 0;
  30. if ((i & (1 << j)) > 0){
  31. cout << arr[j] << " ";
  32. st + = arr[j];
  33. }
  34. }
  35. total + = st *j;
  36. cout << "\n";
  37. }
  38. }
  39.  
  40. int main()
  41. {
  42. int n;
  43. cout << "Enter size of the array\n";
  44. cin >> n;
  45.  
  46. int arr[n];
  47. cout << "Enter Elements of the array\n";
  48. for(int i=0;i<n;i++)
  49. cin >> arr[i];
  50.  
  51. allPossibleSubset(arr,n);
  52.  
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment