human
Minimum sum subsequence such that at least one of every four consecutive elements is picked | function to calculate min sum using dp.
if elements are less than or equal to 4.
save start four element as it is.
compute sum [ ] for all rest elements.
sum [ i ] = ar [ i ] + ( * min_element ( sum + i - 4 , sum + i ) ).
.
Since one of the last 4 elements must be present.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum sum subsequence such that at least one of every four consecutive elements is picked and the other steps required.
 def minSum ( ar , n ) :
	if ( n <= 4 ) :
		return min ( ar )
	sum = [ 0 for i in range ( n ) ]
	sum [ 0 ] = ar [ 0 ]
	sum [ 1 ] = ar [ 1 ]
	sum [ 2 ] = ar [ 2 ]
	sum [ 3 ] = ar [ 3 ]
	for i in range ( 4 , n ) :
		sum [ i ] = ar [ i ] + min ( sum [ i - 4 : i ] )
	return min ( sum [ n - 4 : n ] )
ar = [ 2 , 4 , 1 , 5 , 2 , 3 , 6 , 1 , 2 , 4 ]
n = len ( ar )
print ( " Minimum ▁ sum ▁ = ▁ " , minSum ( ar , n ) )