A Question of Ingestion
Jump to navigation
Jump to search
This is a relatively straightforward knapsack DP problem, except with different rules about capacity modification.
let c = course number let m = calories able to consume let a[i] = calories at each course
can either eat, not eat, or not eat twice: dp[c,m] = max(min(m, a[c])+dp(c+1, 2m/3), dp(c+2,m), dp(c+3, max_m))
it's 20k * 100 so should be plenty fast. You can save time through recursion since ~1/3 entries in DP array will not be filled.