Subsequence that does not contain 3 adjacent elements in the sequence Initially Given a sequence of N positive integer elements. Find the maximum sum of the subsequences obtained from the original sequence for no three consecutive elements in the first sequence in the subsequence)
Input:
- An integer N is the number of elements (1 ≤ 1000)
- The second line writes N integers in the sequence, the elements have values in [1,104] Output:- Print an integer that is the maximum sum
Example: 1. Input: 3 1 2 3 Output: 5
2. Input: 5 3000 2000 1000 3 Output: 5013
- The sequence arr={1,2,3} is the sequence with the largest sum of {2,3} because it is not possible to select all 3 elements into the sequence child
- The sequence arr[] = {3000, 2000, 1000, 3, 10} has the sequence 3000 + 2000 + 3 + 10 = 5013
Can you help me that?
Aucun commentaire:
Enregistrer un commentaire