human
Sum of products of all possible K size subsets of the given array | Function to return the sum of products of all the possible k size subsets.
Initialising all the values to 0.
To store the answer for current value of k.
For k = 1 , the answer will simply be the sum of all the elements.
Filling the table in bottom up manner.
To store the elements of the current row so that we will be able to use this sum for subsequent values of k.
We will subtract previously computed value so as to get the sum of elements from j + 1 to n in the ( i - 1 ) th row.
Driver code"
How can the above be solved in Python?
 ... Can you provide a code to sum of products of all possible K size subsets of the given array and the other steps required?
assistant
#Here is code to sum of products of all possible K size subsets of the given array and the other steps required.
 def sumOfProduct ( arr , n , k ) :
	dp = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
	cur_sum = 0
	for i in range ( 1 , n + 1 ) :
		dp [ 1 ] [ i ] = arr [ i - 1 ]
		cur_sum += arr [ i - 1 ]
	for i in range ( 2 , k + 1 ) :
		temp_sum = 0
		for j in range ( 1 , n + 1 ) :
			cur_sum -= dp [ i - 1 ] [ j ]
			dp [ i ] [ j ] = arr [ j - 1 ] * cur_sum
			temp_sum += dp [ i ] [ j ]
		cur_sum = temp_sum
	return cur_sum
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 3 , 4 ]
	n = len ( arr )
	k = 2
	print ( sumOfProduct ( arr , n , k ) )