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 ?

Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

# | User | Rating |
---|---|---|

1 | Radewoosh | 3443 |

2 | tourist | 3372 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | ksun48 | 3176 |

5 | scott_wu | 3168 |

6 | CongLingDanPaiSh…5 | 3157 |

7 | Benq | 3154 |

8 | Petr | 3139 |

9 | Um_nik | 3138 |

10 | LHiC | 3118 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 195 |

2 | Errichto | 176 |

3 | rng_58 | 158 |

4 | Ashishgup | 157 |

5 | neal | 156 |

6 | tourist | 154 |

7 | Petr | 151 |

8 | PikMike | 150 |

9 | Um_nik | 149 |

10 | kostka | 147 |

10 | Swistakk | 147 |

10 | Vovuh | 147 |

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 ?

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/12/2018 14:06:08 (d3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

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

The upper limit of n is quite large, where 1 ≤ n ≤ 1000000000. How to cater for this with DP?

Probably there is a more general formula?

where we computing the tasks again and again. how would you tell this is dp?

Well the idea is for dp, but you need to use matrices to run it fast, in time (50 is the maximal value of a coin).

I can explain more if you want.

It can be solved in O(1).

We want to count the number of solutions of

x_{1}+ 5x_{2}+ 10x_{3}+ 25x_{4}+ 50x_{5}=N.x_{1}must be congruent with n%5, so is equivalent to count the number of solutions ofx_{1}+x_{2}+ 2x_{3}+ 5x_{4}+ 10x_{5}= ⌊N/ 5⌋ =MLet's suppose (i.e

x_{i}= 5a_{i}+r_{i}), fori≤ 3.We can brute force all possibilities of

r_{i}, now we have to count the solutions ofa_{1}+a_{2}+ 2a_{3}+x_{4}+ 2x_{5}= ⌊ (M-r_{1}-r_{2}- 2r_{3}) / 5⌋ =PGrouping, (

a_{1}+a_{2}+x_{4}) + 2(a_{3}+x_{5}) =Pwhich can be solved byi finally done it but for large inputs stack overflow but already i using long long data type. so now what to do?(https://ideone.com/i929bQ)