i have the problem knapsack has condition N<=100 and w,v<=10^9.
# | User | Rating |
---|---|---|
1 | jiangly | 4039 |
2 | tourist | 3841 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3590 |
5 | ecnerwala | 3542 |
6 | Benq | 3535 |
7 | orzdevinwang | 3526 |
8 | gamegame | 3477 |
9 | heuristica | 3357 |
10 | Radewoosh | 3355 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | atcoder_official | 160 |
3 | Um_nik | 160 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 153 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
i have the problem knapsack has condition N<=100 and w,v<=10^9.
Name |
---|
Any other condition specified? Probably there's.
No has any other condition :v
No constraint on the input array?
a[i],b[i] <=10^9 too
What if you use a map instead of array to save space? Just a guess.
But i will have TLE in the case N=100 and K=10^9
Unless the test cases are weak.
This one has a extra condition $$$w\times v\le 10^9$$$, and I don’t think the problem is solvable without this condition.
LOL it's my problem
Could you please add the link? Or the full statement?
The problem probably has some other stuff if it is meant to be solvable with this range of values. The best you can do with a small $$$N$$$ would be "meet in the middle", which will still be a TLE if your $$$N \leq 100$$$
Vip pro ngừi Việt. As far as i know there's a solution with $$$O(n\sqrt{totalweight})$$$ complexity. So with $$$totalweight=n*w= 1e11$$$ then yeah this solution passes. The idea is that there are about $$$\sqrt{w}$$$ possible sums of subsets when the sum of all of the elements in the set equal $$$w$$$ so we just need to calculate all those possible sums first, then apply the general dp algorithm -> $$$O(n\sqrt{sum})$$$ instead of $$$O(n*sum)$$$. How? I havent implemented it myself but this blog exlains it well and also provides an implementation :D https://codeforces.net/blog/entry/97396
How is that true? Pick elements: $$$1, 2, 4, 8, 16, 32, \ldots, 2^n$$$. Each number from $$$[0, 2^{n+1})$$$ can be obtained as a sum of some subset. We have sum $$$w = 2^{n+1} - 1$$$ and $$$w + 1$$$ possible sums of subsets.
You did not understand that blog. N in that blog is the sum (or maybe more precisely the sum being O(N)). That'd give us O(totalweight^1.5) in here, which is obviously useless.
Yeah you are right, my sincere apologies, I didn't read the blog carefully, what a shame.
Can you add a link to the problem?