1

Given an array A=[6,3,2,1,9,10,2,11] My task is to select elements from the array such that sum of the elements which I pick should not be divisible by M=6 and I can skip at most K=2 elements consecutively. My final goal is to select the elements following above condition and get the maximum sum.

  • means I am not picking

possibilities:

[-,3,2,-,9,-,2,11]=27
[-,3,-,1,9,10,2,-]=25
[-,3,-,1,-,10,2,11]=27
[-,-,2,1,-,10,2,11]=26
[-,-,2,-,9,10,2,11]=34
[-,-,-,1,9,10,2,11]=33
.
.
.
.

and the maximum answer is 34

any DP solution is appreciated

0 Answers0