Count the number of ways to give ranks for N students such that same ranks are possible | Javascript program to calculate the number of ways to give ranks for N students such that same ranks are possible ; Initializing a table in order to store the bell triangle ; Function to calculate the K - th bell number ; If we have already calculated the bell numbers until the required N ; Base case ; First Bell Number ; If the value of the bell triangle has already been calculated ; Fill the defined dp table ; Function to return the number of ways to give ranks for N students such that same ranks are possible ; Resizing the dp table for the given value of n ; Variables to store the answer and the factorial value ; Iterating till N ; Simultaneously calculate the k ! ; Computing the K - th bell number and multiplying it with K ! ; Driver code
var mod = parseInt ( 1e9 + 7 ) ; var dp ; function f ( n , k ) { if ( n < k ) return 0 ; if ( n == k ) return 1 ; if ( k == 1 ) return 1 ; if ( dp [ n ] [ k ] != - 1 ) return dp [ n ] [ k ] ; return dp [ n ] [ k ] = ( ( k * f ( n - 1 , k ) ) % mod + ( f ( n - 1 , k - 1 ) ) % mod ) % mod ; } function operation ( n ) { dp = Array ( n + 1 ) . fill ( ) . map ( ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; for ( i = 0 ; i < n + 1 ; i ++ ) { for ( j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } var ans = 0 , fac = 1 ; for ( k = 1 ; k <= n ; k ++ ) { fac *= k ; ans = ( ans + ( fac * f ( n , k ) ) % mod ) % mod ; } return ans ; } var n = 5 ; document . write ( operation ( n ) + " " ) ;