human
Count ways to build street under given constraints | function to count ways of building a street of n rows.
base case.
ways of building houses in both the spots of ith row.
ways of building an office in one of the two spots of ith row.
total ways for n rows.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to count ways to build street under given constraints and the other steps required.
 def countWays ( n ) :
	dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]
	dp [ 0 ] [ 1 ] = 1
	dp [ 1 ] [ 1 ] = 2
	for i in range ( 2 , n + 1 ) :
		dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]
		dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )
	return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]
if __name__ == " _ _ main _ _ " :
	n = 5
	print ( " Total ▁ no ▁ of ▁ ways ▁ with ▁ n ▁ = " , n , " are : " , countWays ( n ) )