I need help solving a dynamic programming problem

  • Job DurationLess than a week
  • Project LevelBasic Level
  • Project deadlineExpired

Project detail

Here is the problem: Suppose there is a path with `n` positions. Consider the set `S = {A,B,C}`. Each position on the path has an associated non-empty subset of `S`. For each position on the path, we can choose one element from its associated subset. For a given position i on the path, its “value” is determined by the total number of distinct elements from the positions it has access to. The positions it has access to is given by the set `{i-1, i, i+1}` (for `i=1` it is just `{0,1}` and for `i=n` it is just `{n, n-1}`). We want to maximize the sum of the “value” of all positions. So for example, if I had `n=5` and the following subsets for each position `1…5`:
`S1 = {A,C}, S2={A, B}, S3={A,B,C}, S4={A,C}, S5={A,B,C}`
Then one such possible arrangement to maximize the sum would be `[A, B, C, A, B]`, which would be `2 + 3 + 3 + 3 + 2 = 13`. I’d like to write an algorithm that, given a list of subsets (where the nth subset corresponds to the nth position), returns the maximum sum of the value of all positions. This should be an algorithm that is bounded by a polynomial function of n.
Example Input: `[[‘A’, ‘C’], [‘A’, ‘B’], [‘A’, ‘B’, ‘C’], [‘A’, ‘C’], [‘A’, ‘B’, ‘C’]]`
Expected Output: `13`

Skills Required

Industry Categories

Freelancer type required for this project