A Question of Ingestion

From programming_contest
Revision as of 00:48, 2 November 2017 by imported>Kmk21 (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.