https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 165 |
3 | adamant | 161 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
8 | SecondThread | 146 |
10 | pajenegod | 145 |
https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
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?