text: 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: < ? php function permutationCoeff ( $ n , $ k ) { $ P = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= 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 ] ; } $ n = 10 ; $ k = 2 ; echo " Value ▁ of ▁ P ( " , $ n , " ▁ , " , $ k , " ) ▁ is ▁ " , permutationCoeff ( $ n , $ k ) ; ? >