human
Give me a code to sum of all subsets of a given size ( = K ) and the other steps required given the following:
Sum of all subsets of a given size ( = K ) | Function to find the sum of all sub - sets of size K.
Frequency of each array element in summation equation ..
calculate factorial of n - 1.
calculate factorial of k - 1.
calculate factorial of n - k.
Calculate sum of array ..
Sum of all subsets of size k ..
Driver Code"
Solution in Python:
assistant
#Here is code to sum of all subsets of a given size ( = K ) and the other steps required.
 def findSumOfAllSubsets ( arr , n , k ) :
	factorial_N = 1
	factorial_d = 1
	factorial_D = 1
	for i in range ( 1 , n , 1 ) :
		factorial_N *= i
	for i in range ( 1 , k , 1 ) :
		factorial_d *= i
	for i in range ( 1 , n - k + 1 , 1 ) :
		factorial_D *= i
	freq = factorial_N // ( factorial_d * factorial_D )
	sum = 0
	for i in range ( n ) :
		sum += arr [ i ]
	sum = sum * freq
	print ( " Sum ▁ of ▁ all ▁ subsets ▁ of ▁ size ▁ = ▁ " , k , " ▁ is ▁ = > " , sum )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 4 , 5 ]
	n = 4
	k = 2
	findSumOfAllSubsets ( arr , n , k )