Mean of minimum of all possible K | C ++ program for the above approach ; Function to find the value of nCr ; Base Case ; Find nCr recursively ; Function to find the expected minimum values of all the subsets of size K ; Find the factorials that will be used later ; Find the factorials ; Total number of subsets ; Stores the sum of minimum over all possible subsets ; Iterate over all possible minimum ; Find the mean over all subsets ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int nCr ( int n , int r , int f [ ] ) { if ( n < r ) { return 0 ; } return f [ n ] / ( f [ r ] * f [ n - r ] ) ; } int findMean ( int N , int X ) { int f [ N + 1 ] ; f [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { f [ i ] = f [ i - 1 ] * i ; } int total = nCr ( N , X , f ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { count += nCr ( N - i , X - 1 , f ) * i ; } double E_X = double ( count ) / double ( total ) ; cout << setprecision ( 10 ) << E_X ; return 0 ; } int main ( ) { int N = 3 , X = 2 ; findMean ( N , X ) ; return 0 ; }