Can someone help me how to solve this question https://acm.timus.ru/problem.aspx?space=1&num=1918
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Can someone help me how to solve this question https://acm.timus.ru/problem.aspx?space=1&num=1918
Name |
---|
Untested solution : We can see that for each $$$i$$$ we can go to some $$$j$$$ or $$$i-1$$$ using the handles. Now let $$$dp_{i,j}$$$ denote a way to position the first $$$i$$$ handles in a way such that you can reach $$$j$$$. Notice that if $$$j$$$ is reachable, all values below $$$j$$$ are also reachable.
This means at least one handle is at the $$$jth$$$ position, and none are at a larger position. Now we can see that $$$dp_{i,j} = dp_{i-1,j}\times j + \sum_{k=0}^{j-1} dp_{i-1,k}$$$.
The first term is for $$$j$$$ being reachable from before and the second term is setting the $$$ith$$$ handle to $$$j$$$ so that $$$j$$$ is now reachable. This can be computed in $$$O(n^2)$$$ by using prefix sums.
The base term is $$$dp_{0,1} = 1$$$ and the rest are $$$0$$$.
Thanks... understood
:0