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 | 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 | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
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