This question evaluates dynamic programming and sequence optimization skills, focusing on modeling cumulative build costs with adjacency distance penalties and handling variants such as skipping a factory.
You must choose construction options for factories to minimize a total cost.
Input format:
options[i]
is a list of options for factory
i
.
[cost, distance]
.
For 3 factories, an example input is:
options = [
[[10, 0], [20, 0], [35, 0]],
[[35, 0], [50, 0], [25, 0]],
[[30, 0], [5, 0], [40, 0]]
]
If you pick exactly one option per built factory, define:
cost
.
abs(distance[i] - distance[i+1])
.
Total = build cost + distance penalty.
N
factories. Compute the minimum efficiently.
N-1
factories, skipping (not building) exactly one factory. Distance penalty applies between adjacent built factories in their original order (i.e., skipping connects its neighbors). Compute the minimum.
Return the minimum total cost (and optionally the chosen options if requested).
N
and number of options per factory can be large enough that brute force over all combinations may be too slow.