human
Find all distinct subset ( or subsequence ) sums of an array | sum denotes the current sum of the subset currindex denotes the index we have reached in the given array.
This function mainly calls recursive function distSumRec ( ) to generate distinct sum subsets . And finally prints the generated subsets ..
Print the result.
Driver code"
Solution in Python:
assistant
#Here is code to find all distinct subset ( or subsequence ) sums of an array and the other steps required.
 def distSumRec ( arr , n , sum , currindex , s ) :
	if ( currindex > n ) :
		return
	if ( currindex == n ) :
		s . add ( sum )
		return
	distSumRec ( arr , n , sum + arr [ currindex ] , currindex + 1 , s )
	distSumRec ( arr , n , sum , currindex + 1 , s )
def printDistSum ( arr , n ) :
	s = set ( )
	distSumRec ( arr , n , 0 , 0 , s )
	for i in s :
		print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 4 , 5 , 6 ]
	n = len ( arr )
	printDistSum ( arr , n )