text: Ways to multiply n elements with an associative operation | C ++ code to find number of ways to multiply n elements with an associative operation ; Function to find the required factorial ; Function to find nCr ; function to find the number of ways ; Driver code
code: # include <bits/stdc++.h> NEW_LINE using namespace std ; int fact ( int n ) { if ( n == 0 n == 1 ) return 1 ; int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ans ; } int nCr ( int n , int r ) { int Nr = n , Dr = 1 , ans = 1 ; for ( int i = 1 ; i <= r ; i ++ ) { ans = ( ans * Nr ) / ( Dr ) ; Nr -- ; Dr ++ ; } return ans ; } int solve ( int n ) { int N = 2 * n - 2 ; int R = n - 1 ; return nCr ( N , R ) * fact ( n - 1 ) ; } int main ( ) { int n = 6 ; cout << solve ( n ) ; return 0 ; }