Блог пользователя OmaeWaMouShenDeiru

Автор OmaeWaMouShenDeiru, 10 лет назад, По-английски

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

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

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

»
10 лет назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

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).