how to Find sum of maximum- minimum of all possible subset of given array
for example
given array is 1
all posible subsets are [[], [1]]
1-1=0
given array is 1 2
all posible subsets are [[], [1], [2], [1, 2]]
1-1+2-2+2-1=1
given array is 1 2 3
all posible subsets are [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
1-1+2-2+2-1+3-3+3-1+3-2+3-1=6
given array is 1 2 3 4
all posible subsets are [[], [1], [2], [1, 2], [3], [1, 3], [4], [2, 3], [1, 4], [1, 2, 3], [2, 4], [1, 2, 4], [3, 4], [1, 3, 4], [2, 3, 4], [1, 2, 3, 4]]
ans=23
given array is 2 3 4 5
all posible subsets are [[], [1], [2], [1, 2], [3], [1, 3], [4], [2, 3], [1, 4], [5], [1, 2, 3], [2, 4], [1, 5], [1, 2, 4], [3, 4], [2, 5], [1, 3, 4], [1, 2, 5], [3, 5], [2, 3, 4], [1, 3, 5], [4, 5], [1, 2, 3, 4], [2, 3, 5], [1, 4, 5], [1, 2, 3, 5], [2, 4, 5], [1, 2, 4, 5], [3, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5], [1, 2, 3, 4, 5]]
ans= 72
See Question&Answers more detail:
os