human
Number of K length subsequences with minimum sum | Function to return the value of Binomial Coefficient C ( n , k ).
Calculate value of Binomial Coefficient in bottom up manner.
Base Cases.
Calculate value using previously stored values.
Function to return the count of valid subsequences.
Sort the array.
Maximum among the minimum K elements.
Y will store the frequency of num in the minimum K elements.
cntX will store the frequency of num in the complete array.
Driver code"
Solution in Python:
assistant
#Here is code to number of K length subsequences with minimum sum and the other steps required.
 def binomialCoeff ( n , k ) :
	C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( k + 1 ) ]
	for i in range ( 0 , n + 1 ) :
		for j in range ( 0 , min ( i , k ) + 1 ) :
			if ( j == 0 or j == i ) :
				C [ i ] [ j ] = 1
			else :
				C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]
	return C [ n ] [ k ]
def cntSubSeq ( arr , n , k ) :
	arr . sort ( )
	num = arr [ k - 1 ] ;
	Y = 0 ;
	for i in range ( k - 1 , - 1 , 1 ) :
		if ( arr [ i ] == num ) :
			Y += 1
	cntX = Y ;
	for i in range ( k , n ) :
		if ( arr [ i ] == num ) :
			cntX += 1
	return binomialCoeff ( cntX , Y )
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
k = 2
print ( cntSubSeq ( arr , n , k ) )