Number of arrays of size N whose elements are positive integers and sum is K | Return nCr ; C [ 0 ] = 1 ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Return the number of array that can be formed of size n and sum equals to k . ; Driver Code
def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ 0 ] * ( k + 1 ) ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , k ) , 0 , - 1 ) : NEW_LINE INDENT C [ j ] = C [ j ] + C [ j - 1 ] ; NEW_LINE DEDENT DEDENT return C [ k ] ; NEW_LINE DEDENT def countArray ( N , K ) : NEW_LINE INDENT return binomialCoeff ( K - 1 , N - 1 ) ; NEW_LINE DEDENT N = 2 ; NEW_LINE K = 3 ; NEW_LINE print ( countArray ( N , K ) ) ; NEW_LINE