Hi, I can't solve it for a long time. There are really short codes, but I can't get the main idea :( Thanks for help.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Hi, I can't solve it for a long time. There are really short codes, but I can't get the main idea :( Thanks for help.
Name |
---|
Ok Let's notice a fact That f(a1, a2, ..., an) = |a1| — f(a1, a2) + |a2| — f(a2, a3) .... + |ai| — f(ai, a[i+1) + ... + |an|
Now just solve it n ^ 2 and after that solve it nk
How?
dp[i] = lets partition it till i-1
for (int l = 0; l < n; ++l)
for (int r = 1; r <= n; ++r)
dp[r] = min(dp[r], dp[l] — (r != n? lcp(a[l], a[r]): 0) + |a[l]| + |a[l + 1]| + ... + |a[r — 1]| — f(a[l], a[l + 1]) — f(a[l+1], a[l+2]).... f(a[r — 2], a[r — 1) (this can be found with partial sum));
I can't understand :(
well if you partition the sequence into two subsequences the sequence will be like this
c means it belongs to subsequence c
b means it belongs to subsequence b
bbbcccbbccbbbb
in those fors dp[r] = the best way to partition it till r which r and r — 1 are different and dp[n] is a special case where the nth element doesnt exist
in those 2 fors l means the first place before r where l and l — 1 are different
the things that will be added are -f(l, l + 1) -f(l + 1, l + 2) ... -f(r — 2, r — 1) and the sizes of the elements by that lcp i mean (l != 0? |f(a[l-1], a[r])|: 0)
if you didn't understand tell me again ;D it will be appreciated if you tell the place which you can't understand too
Actually I can't understand anything, there is some formulas and something but what can I do with them? :D
http://mirror.codeforces.com/blog/entry/1976
It's a decent explanation even with Google Translate.
I read it but I can't understand with translate.
First, some notation. We have binary strings s1... sn each of length k. Let si(l) denote the prefix of si of length l.
Now, let dp[x][suf] be the minimum cost for strings s1... sx given that one subsequence ends in sx and the other ends in suf. Note that suf can have length between 0 and k. Our state transition is:
Here is the logic behind the transition. In order to make two subsequences, one ending with sx and the other in suf, we can either append sx to the subsequence ending with sx - 1, or we can append sx to a subsequence ending in sx(l) where 0 ≤ l ≤ k. In the later case, we will end up with one subsequence ending with sx and the other subsequence ending with sx - 1, so we need only evaluate this case if sx - 1 ends in suf.
I'll let you figure out the details of the implementation as an exercise. You'll need to figure out how to handle state transitions in an efficient manner.
I solved it yesterday, but I really appreciated for your help. Thanks.