A Question of Ingestion: Difference between revisions

From programming_contest
Jump to navigation Jump to search
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..."
 
imported>Kmk21
 
(No difference)

Latest revision as of 00:48, 2 November 2017

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.