Editorial for ICPC NAQ 2016 H - Nine Packs


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
  • Considering only hotdog packs h1,,hi, let opth(i,k) denote the minimum number of packs you need to buy to have exactly k hotdogs, or + if impossible.
  • Similarly, let optb(i,k) denote the corresponding value for the packs of buns b1,,bi.
  • If C=min(i=1Hhi,i=1Bbi), the answer is: min1kCoptb(B,k)+opth(H,k)
  • Note that C1001000=105.
  • Computing opth(i,k) is an instance of the Knapsack problem (or a variant thereof), and can be solved in a similar manner as follows.
  • Based on whether we buy the ith pack of hotdogs (hi) or not, we get the following recurrence: opth(i,k)=min(1+opth(i1,khi),opth(i1,k))
  • We also have the base cases: opth(i,k)={0if k=0+if i=0 or k<0
  • We have a similar recursion for optb(i,k).
  • Finally, opth(H,k) and optb(B,k) can be computed for all 1kC in O((B+H)C) using dynamic programming (or memoization).

Comments

There are no comments at the moment.