problem link->MCOINS — Coins Game
my code-> codepad
# | User | Rating |
---|---|---|
1 | tourist | 3857 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3463 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 162 |
3 | Dominater069 | 160 |
4 | Qingyu | 158 |
5 | atcoder_official | 157 |
5 | Um_nik | 157 |
7 | adamant | 151 |
7 | djm03178 | 151 |
7 | luogu_official | 151 |
10 | awoo | 146 |
problem link->MCOINS — Coins Game
my code-> codepad
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.
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 :)