problem link->MCOINS — Coins Game

my code-> codepad

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

1 | tourist | 3602 |

2 | Petr | 3294 |

3 | moejy0viiiiiv | 3240 |

4 | TakanashiRikka | 3178 |

5 | W4yneb0t | 3162 |

6 | LHiC | 3149 |

7 | Um_nik | 3148 |

8 | izrak | 3109 |

9 | ershov.stanislav | 3105 |

10 | Radewoosh | 3094 |

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

1 | rng_58 | 182 |

2 | Errichto | 167 |

3 | csacademy | 166 |

3 | tourist | 166 |

5 | Petr | 164 |

6 | Swistakk | 156 |

7 | Zlobober | 147 |

8 | zscoder | 144 |

9 | matthew99 | 141 |

10 | Radewoosh | 138 |

10 | GlebsHP | 138 |

problem link->MCOINS — Coins Game

my code-> codepad

↑

↓

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/28/2017 17:49:35 (c3).

Desktop version, switch to mobile version.

User lists

Name |
---|

Your solution has complexity of O(N) per single tower, which results in O(m*N) per test-case which unfortunately is not fast enough. One could easily notice, however, that the dp states will be the same for the same K and L and are independent of N, so you can compute the states only for the largest tower (biggest N), thus resulting in O(N) per test-case.

I managed to get AC modifying your code to do just that, so feel free to ask any questions :)

sorry for my late reply. would u kindly describe the way more elaborately?? since i am new to dp i find it difficult :( any clue,hints,idea will be greatly appreciated :)

Well let's consider the example. We have :

So what your solution will do is calculate the states from 1 to 3, then from 1 to 12, then from 1 to 113, then from 1 to 25714, then from 1 to 88888. However you can instead calculate them just once from 1 to 88888 and then use dp[3], dp[12], dp[113], dp[25714] and dp[88888] to answer your queries. Do you understand what I mean?

yes Enchom bro,i completely understand your idea.even if i never understand a problem so well before :D i implement as you said and got accepted :) :) thank u so much.

Although I got AC in one go the time was 0.34seconds.But after optimizing my algorithm according to your suggestion time reduced to 0.01seconds.Thank You ;)

hey.. can you please give me any hints on writing a recursive solution to this problem.. I would be so grateful if you do :D

Click

thanks for the explanation... got AC using recursion :)