if i need to divide the array into two subsets with the minimum diference between the sum of the two sets what i can do i know the dp(idx,sum) solution but i need faster one
# | 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 |
Name |
---|
Consider the DP:
Then think of the path of the DP that leads to the optimal solution. Since
sum
is minimized in the last step, maybe it's also small in every intermediate step? This is not always true. But what if we shuffle the array?Then we can think of each $$$a_{i}$$$ as an independent random variable (which is not really true, but close enough for CP purposes), and
sum
might follow something like a random walk, which is normally distributed according to CLT. Due to linearity of variance of independent variables, we expect that $$$|\texttt{sum}|$$$ is always $$$O(\sqrt{N}\cdot\max\{ a_{i}\})$$$ with high probability.So this means we can write above DP solution like this:
(Where $$$\texttt{LIMIT} \in O(\sqrt{N}\cdot\max\{ a_{i}\})$$$ -- multiply by 3 or 4) And we still get the correct answer with high probability, assuming that
a
has been shuffled beforehand. With this method we a probabilistic solution with complexity $$$O(N^{1.5}\cdot\max\{ a_{i}\})$$$ instead of the classic $$$O(N^{2}\cdot\max\{ a_{i}\})$$$Thanks