Ways to form a group from three groups with given constraints | javascript program to find the number of ways to form the group of peopls ; Function to pre - compute the Combination using DP ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; return C [ n ] [ k ] ; ; Function to find the number of ways ; Function to pre - compute ; Sum the Zci ; Iterate for second position ; Iterate for first position ; Multiply the common Combination value ; Driver Code
var C = Array ( 1000 ) . fill ( ) . map ( ( ) => Array ( 1000 ) . fill ( 0 ) ) ; function binomialCoeff ( n ) { var i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } } function numberOfWays ( x , y , z ) { binomialCoeff ( Math . max ( x , Math . max ( y , z ) ) ) ; var sum = 0 ; for ( i = 1 ; i <= z ; i ++ ) { sum = ( sum + C [ z ] [ i ] ) ; } var sum1 = 0 ; for ( i = 1 ; i <= y ; i ++ ) { for ( j = i + 1 ; j <= x ; j ++ ) { sum1 = ( sum1 + ( C [ y ] [ i ] * C [ x ] [ j ] ) ) ; } } sum1 = ( sum * sum1 ) ; return sum1 ; } var x = 3 ; var y = 2 ; var z = 1 ; document . write ( numberOfWays ( x , y , z ) ) ;