https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
# | User | Rating |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | adamant | 164 |
2 | awoo | 164 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
This problem can be solved in a similar way as MAXMATCH.
You can first find maximum matching of the two strings by keeping s fixed and varying r. To achieve that you can construct polynomial for each of the different character, by raising x to the powers of indexes in
s
and to negative of powers of index inr
. For example considers = ATCAAA
r = ACAA
Now for character
A
, and s you will construct polynomial x0 + x3 + x4 + x5And for character
A
, and r you will construct x0 + x - 2 + x - 3.Now when you multiply them, the coefficient of xk will represent number of matching indexes for
A
in kth shift.You can just sum that over all four characters and answer will
res.size() - maximum_matching
But, how we will multiply them? FFT multiplies polynomials with non-zero powers of x.
Can you please explain why r contains the negative of powers of index?