human
Find number of times a string occurs as a subsequence in given string | Iterative DP function to find the number of times the second string occurs in the first string , whether continuous or discontinuous.
Create a table to store results of sub - problems.
If first string is empty.
If second string is empty.
Fill lookup [ ] [ ] in bottom up manner.
If last characters are same , we have two options - 1. consider last characters of both strings in solution 2. ignore last character of first string.
If last character are different , ignore last character of first string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find number of times a string occurs as a subsequence in given string and the other steps required.
 def count ( a , b ) :
	m = len ( a )
	n = len ( b )
	lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]
	for i in range ( n + 1 ) :
		lookup [ 0 ] [ i ] = 0
	for i in range ( m + 1 ) :
		lookup [ i ] [ 0 ] = 1
	for i in range ( 1 , m + 1 ) :
		for j in range ( 1 , n + 1 ) :
			if a [ i - 1 ] == b [ j - 1 ] :
				lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]
			else :
				lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]
	return lookup [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
	a = " GeeksforGeeks "
	b = " Gks "
	print ( count ( a , b ) )