human
Give me a code to minimum cost to complete given tasks if cost of 1 , 7 and 30 days are given and the other steps required given the following:
Minimum cost to complete given tasks if cost of 1 , 7 and 30 days are given | Function to find the minimum cost to hire the workers for the given days in the array days [ ].
Initialize the array dp.
Minimum Cost for Nth day.
Poleter of the array arr [ ].
Traverse from right to left.
If worker is hired for 1 day.
If worker is hired for 7 days.
If worker is hired for 30 days.
Update the value of dp [ i ] as minimum of 3 options.
If the day is not at the array arr [ ].
Return the answer.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum cost to complete given tasks if cost of 1 , 7 and 30 days are given and the other steps required.
 def MinCost ( days , cost , N ) :
	size = days [ N - 1 ] + 1
	dp = [ 0 for i in range ( size ) ]
	dp [ size - 1 ] = min ( cost [ 0 ] , min ( cost [ 1 ] , cost [ 2 ] ) )
	ptr = N - 2
	for i in range ( size - 2 , 0 , - 1 ) :
		if ( ptr >= 0 and days [ ptr ] == i ) :
			val1 = dp [ i + 1 ] + cost [ 0 ]
			val2 = cost [ 1 ] + ( 0 if ( i + 7 >= size ) else dp [ i + 7 ] )
			val3 = cost [ 2 ] + ( 0 if ( i + 30 >= size ) else dp [ i + 30 ] )
			dp [ i ] = min ( val1 , min ( val2 , val3 ) )
			ptr -= 1 ;
		else :
			dp [ i ] = dp [ i + 1 ]
	return dp [ 1 ]
arr = [ 2 , 4 , 6 , 7 , 8 , 10 , 17 ]
cost = [ 3 , 8 , 20 ]
N = len ( arr )
print ( MinCost ( arr , cost , N ) )