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

Автор ultranoobs, история, 7 лет назад, По-английски

i am stuck with this dp problem , can any someone explain me the state of dp for this problem ? problem link is Question

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

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

This is a difficult DP problem until you know the trick. When would a triangle be invalid? Only when one of the side lengths is >= 1/2 of the total sum. With this in mind we can count how many assignments are invalid triangles, rather than how many assignments are valid triangles. This problem is significantly easier — we have 2 parts to our state: current sum and current item. At each spot we have 2 choices — add to our sum or don't. Succeed when our value reaches 1/2 of the total array sum. Total time is O(2 choices * 300 indexes * 300^2 max sum). We can recover the answer by taking 3^N — 3 * the result of our DP.