text: Permutation Coefficient | A Dynamic Programming based solution that uses table P [ ] [ ] to calculate the Permutation Coefficient ; Returns value of Permutation Coefficient P ( n , k ) ; Calculate value of Permutation Coefficient in bottom up manner ; Base Cases ; Calculate value using previosly stored values ; This step is important as P ( i , j ) = 0 for j > i ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE int permutationCoeff ( int n , int k ) { int P [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= std : : min ( i , k ) ; j ++ ) { if ( j == 0 ) P [ i ] [ j ] = 1 ; else P [ i ] [ j ] = P [ i - 1 ] [ j ] + ( j * P [ i - 1 ] [ j - 1 ] ) ; P [ i ] [ j + 1 ] = 0 ; } } return P [ n ] [ k ] ; } int main ( ) { int n = 10 , k = 2 ; printf ( " Value ▁ of ▁ P ( % d , ▁ % d ) ▁ is ▁ % d ▁ " , n , k , permutationCoeff ( n , k ) ) ; return 0 ; }