human
Give me a code to sequences of given length where every element is more than or equal to twice of previous and the other steps required given the following:
Sequences of given length where every element is more than or equal to twice of previous | DP based function to find the number of special sequence.
define T and build in bottom manner to store number of special sequences of length n and maximum value m.
Base case : If length of sequence is 0 or maximum value is 0 , there cannot exist any special sequence.
if length of sequence is more than the maximum value , special sequence cannot exist.
If length of sequence is 1 then the number of special sequences is equal to the maximum value For example with maximum value 2 and length 1 , there can be 2 special sequences { 1 } , { 2 }.
otherwise calculate.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to sequences of given length where every element is more than or equal to twice of previous and the other steps required.
 def getTotalNumberOfSequences ( m , n ) :
	T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
	for i in range ( m + 1 ) :
		for j in range ( n + 1 ) :
			if i == 0 or j == 0 :
				T [ i ] [ j ] = 0
			elif i < j :
				T [ i ] [ j ] = 0
			elif j == 1 :
				T [ i ] [ j ] = i
			else :
				T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]
	return T [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
	m = 10
	n = 4
	print ( ' Total ▁ number ▁ of ▁ possible ▁ sequences ▁ ' , getTotalNumberOfSequences ( m , n ) )