human
Minimum time to write characters using insert , delete and copy operation | Python3 program to write characters in minimum time by inserting , removing and copying operation.
method returns minimum time to write ' N ' characters.
declare dp array and initialize with zero.
first char will always take insertion time.
loop for ' N ' number of times.
if current char count is even then choose minimum from result for ( i - 1 ) chars and time for insertion and result for half of chars and time for copy.
if current char count is odd then choose minimum from result for ( i - 1 ) chars and time for insertion and result for half of chars and time for copy and one extra character deletion.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum time to write characters using insert , delete and copy operation and the other steps required.
 def minTimeForWritingChars ( N , insert , remov , cpy ) :
	if N == 0 :
		return 0
	if N == 1 :
		return insert
	dp = [ 0 ] * ( N + 1 )
	dp [ 1 ] = insert
	for i in range ( 2 , N + 1 ) :
		if i % 2 == 0 :
			dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i // 2 ] + cpy )
		else :
			dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) // 2 ] + cpy + remov )
	return dp [ N ]
if __name__ == " _ _ main _ _ " :
	N = 9
	insert = 1
	remov = 2
	cpy = 1
	print ( minTimeForWritingChars ( N , insert , remov , cpy ) )