Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2 4 3 1 7 9 4 5
- All possible subset a maximum number - a minimum number = all subset result summations
- -----------
- Tree connecting node sum
- (n-chieldtree)*chieldtree
- -----------
- 1 2 7 9 6 8 4 3
- All sub array like
- 7 9 6
- length = 3 *(7+9+6)
- #include <bits/stdc++.h>
- using namespace std;
- void allPossibleSubset(int arr[],int n)
- {
- int count = pow(2,n);
- for (int i = 1; i <=count; i++)
- {
- int total=0;
- for (int j = 1; j <=n; j++)
- {
- int st = 0;
- if ((i & (1 << j)) > 0){
- cout << arr[j] << " ";
- st + = arr[j];
- }
- }
- total + = st *j;
- cout << "\n";
- }
- }
- int main()
- {
- int n;
- cout << "Enter size of the array\n";
- cin >> n;
- int arr[n];
- cout << "Enter Elements of the array\n";
- for(int i=0;i<n;i++)
- cin >> arr[i];
- allPossibleSubset(arr,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment