Advertisement
Kamend1

The Tyrant

Aug 4th, 2023
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. def find_minimum_sum_subsequence(sequence):
  2. n = len(sequence)
  3. if n <= 4:
  4. return sum(sequence)
  5.  
  6. dp = [0] * n
  7. dp[0] = sequence[0]
  8. dp[1] = sequence[1]
  9. dp[2] = sequence[2]
  10. dp[3] = sequence[3]
  11.  
  12. for i in range(4, n):
  13. dp[i] = min(dp[i-4], dp[i-3], dp[i-2], dp[i-1]) + sequence[i]
  14.  
  15. return min(dp[-1], dp[-2], dp[-3], dp[-4])
  16.  
  17.  
  18. sequence = list(map(int, input().split()))
  19. result = find_minimum_sum_subsequence(sequence)
  20. print(result)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement