human
Find minimum sum such that one of every three consecutive elements is taken | A utility function to find minimum of 3 elements.
Returns minimum possible sum of elements such that an element out of every three consecutive elements is picked ..
Create a DP table to store results of subproblems . sum [ i ] is going to store minimum possible sum when arr [ i ] is part of the solution ..
When there are less than or equal to 3 elements.
Iterate through all other elements.
Driver code"
Solution in Python:
assistant
#Here is code to find minimum sum such that one of every three consecutive elements is taken and the other steps required.
 def minimum ( a , b , c ) :
	return min ( min ( a , b ) , c ) ;
def findMinSum ( arr , n ) :
	sum = [ ]
	sum . append ( arr [ 0 ] )
	sum . append ( arr [ 1 ] )
	sum . append ( arr [ 2 ] )
	for i in range ( 3 , n ) :
		sum . append ( arr [ i ] + minimum ( sum [ i - 3 ] , sum [ i - 2 ] , sum [ i - 1 ] ) )
	return minimum ( sum [ n - 1 ] , sum [ n - 2 ] , sum [ n - 3 ] )
arr = [ 1 , 2 , 3 , 20 , 2 , 10 , 1 ]
n = len ( arr )
print ( " Min ▁ Sum ▁ is ▁ " , findMinSum ( arr , n ) )