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

Автор Polyn0mial, история, 4 года назад, По-английски

Link to the problem I use bottom up DP, where $$$dp[\text{mask of visited vertices}][\text{ending vertex}]$$$. I'm pretty sure my time complexity is $$$O(N \cdot 2^N + 2^N \cdot N^2)$$$ however it gives TLE. Are there any way to optimize my code, and what's the reason for TLE (probably big constant factor?)

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

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Your dp idea could work, if you eliminate the N^2 factor. Try using a top-bottom approach, so start with the full mask and ending, and work to the bottom (recursion should be an easy implementation). don't forget to use memoization in that case, since you don't want to compute the same value more than once.