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

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

Link

Does someone know a special fact about this conjecture that could help to get a complexity lower than O(180*n), which is the one you get using a dp approach, I tried these two codes:

http://ideone.com/XN4td http://ideone.com/cWhNR (tried to use pointers to speed it up)

but both give me TLE.

Теги math, dp
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

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

I've just got AC.

You should use these two ideas to get AC.

  • Use shouldn't solve the general knapsack problem to get the first answer for the test case. Surprisingly, the Pollock's conjecture will help you to solve this problem efficiently :) Consider the fact, that possible answers are 1,2,3,4,5. So you can just brute-force the answers for 1,2 and 3. Then you can add tetrahedral number for every x that d[x] = 3, thus finding all the y that d[y] = 4. The answer for the remaining numbers is 5.

  • There are only 45 odd tetrahedral numbers and there are no any conjectures about them. So you should use the most general dp approach.

If you have any more questions about this solution feel free to ask them :)

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    Thanks, I haven't thought about how to deal with the case of d[y] = 4. Nice!