Count all unique outcomes possible by performing S flips on N coins | Dimensions of the DP table ; Stores the dp states ; Function to recursively count the number of unique outcomes possible by performing S flips on N coins ; Base Case ; If the count for the current state is not calculated , then calculate it recursively ; Otherwise return the already calculated value ; Driver Code
size = 100 NEW_LINE ans = [ [ 0 for i in range ( size ) ] for j in range ( size ) ] NEW_LINE def numberOfUniqueOutcomes ( n , s ) : NEW_LINE INDENT if ( s < n ) : NEW_LINE INDENT ans [ n ] [ s ] = 0 ; NEW_LINE DEDENT elif ( n == 1 or n == s ) : NEW_LINE INDENT ans [ n ] [ s ] = 1 ; NEW_LINE DEDENT elif ( ans [ n ] [ s ] == 0 ) : NEW_LINE INDENT ans [ n ] [ s ] = ( numberOfUniqueOutcomes ( n - 1 , s - 1 ) + numberOfUniqueOutcomes ( n - 1 , s - 2 ) ) NEW_LINE DEDENT return ans [ n ] [ s ] ; NEW_LINE DEDENT N = 5 NEW_LINE S = 8 NEW_LINE print ( numberOfUniqueOutcomes ( N , S ) ) NEW_LINE