Permutation Coefficient | Returns value of Permutation Coefficient P ( n , k ) ; Calculate value of Permutation Coefficient in bottom up manner ; Base cases ; Calculate value using previously stored values ; This step is important as P ( i , j ) = 0 for j > i ; Driver Code
def permutationCoeff ( n , k ) : NEW_LINE INDENT P = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , k ) + 1 ) : NEW_LINE INDENT if ( j == 0 ) : NEW_LINE INDENT P [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT P [ i ] [ j ] = P [ i - 1 ] [ j ] + ( j * P [ i - 1 ] [ j - 1 ] ) NEW_LINE DEDENT if ( j < k ) : NEW_LINE INDENT P [ i ] [ j + 1 ] = 0 NEW_LINE DEDENT DEDENT DEDENT return P [ n ] [ k ] NEW_LINE DEDENT n = 10 NEW_LINE k = 2 NEW_LINE print ( " Value ▁ fo ▁ P ( " , n , " , ▁ " , k , " ) ▁ is ▁ " , permutationCoeff ( n , k ) , sep = " " ) NEW_LINE