Блог пользователя Ram_Negative

Автор Ram_Negative, история, 8 лет назад, По-английски

hi how to solve the problem change from the spoj (http://www.spoj.com/problems/TPC07/)

i read concrete mathematics chapter 7 about coin change. but i can't able to understand can anybody help me to get idea about solving this problem ?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -21 Проголосовать: не нравится

This is a dynamic programming problem. First learn something about it, then approach this problem

»
8 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

It can be solved in O(1).

We want to count the number of solutions of x1 + 5x2 + 10x3 + 25x4 + 50x5 = N.

x1 must be congruent with n%5, so is equivalent to count the number of solutions of x1 + x2 + 2x3 + 5x4 + 10x5 = ⌊ N / 5⌋ = M

Let's suppose (i.e xi = 5ai + ri), for i ≤ 3.

We can brute force all possibilities of ri, now we have to count the solutions of

a1 + a2 + 2a3 + x4 + 2x5 = ⌊ (M - r1 - r2 - 2r3) / 5⌋ = P

Grouping, (a1 + a2 + x4) + 2(a3 + x5) = P which can be solved by