OmaeWaMouShenDeiru's blog

By OmaeWaMouShenDeiru, 10 years ago, In English

Hello ,

I tried to solve this problem using subset sum algorithm and precalculation for all numbers which satisfy the given condition, But i got alot of TLE.

is there any fast subset sum algorithm better than O(n^2) ??

This is the problem :http://www.ahmed-aly.com/p.jsp?ID=172

And this is my code : Edit after AC :D

Thanks

»
10 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

The DP table is very sparse, try to solve it using recursion.

»
10 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

simple dp solution with O(SUM*N) will work i think

Edit: solved it, with top-down dp and some small optimisations (sieved all ps numbers (it seems those which are less that 1101 are not so many, used fast i/o + one opt in the main loop).