human
Find the number of Chicks in a Zoo at Nth day | Function to return the number of chicks on the nth day.
Size of dp [ ] has to be at least 6 ( 1 - based indexing ).
Every day current population will be three times of the previous day.
Manually calculated value.
From 8 th day onwards.
Chick population decreases by 2 / 3 everyday . For 8 th day on [ i - 6 ] i . e 2 nd day population was 3 and so 2 new born die on the 6 th day and so on for the upcoming days.
Driver code"
Solution in Python:
assistant
#Here is code to find the number of Chicks in a Zoo at Nth day and the other steps required.
 def getChicks ( n ) :
	size = max ( n , 7 ) ;
	dp = [ 0 ] * size ;
	dp [ 0 ] = 0 ;
	dp [ 1 ] = 1 ;
	for i in range ( 2 , 7 ) :
		dp [ i ] = dp [ i - 1 ] * 3 ;
	dp [ 6 ] = 726 ;
	for i in range ( 8 , n + 1 ) :
		dp [ i ] = ( dp [ i - 1 ] - ( 2 * dp [ i - 6 ] // 3 ) ) * 3 ;
	return dp [ n ] ;
n = 3 ;
print ( getChicks ( n ) ) ;