human
Count number of strings ( made of R , G and B ) using given combination | Function to calculate number of strings.
Store factorial of numbers up to n for further computation.
Find the remaining values to be added.
Make all possible combinations of R , B and G for the remaining value.
Compute permutation of each combination one by one and add them ..
Return total no . of strings / permutation.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count number of strings ( made of R , G and B ) using given combination and the other steps required.
 def possibleStrings ( n , r , b , g ) :
	fact = [ 0 for i in range ( n + 1 ) ]
	fact [ 0 ] = 1
	for i in range ( 1 , n + 1 , 1 ) :
		fact [ i ] = fact [ i - 1 ] * i
	left = n - ( r + g + b )
	sum = 0
	for i in range ( 0 , left + 1 , 1 ) :
		for j in range ( 0 , left - i + 1 , 1 ) :
			k = left - ( i + j )
			sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )
	return sum
if __name__ == ' _ _ main _ _ ' :
	n = 4
	r = 2
	b = 0
	g = 1
	print ( int ( possibleStrings ( n , r , b , g ) ) )