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

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

Hi. I was working on a DP problem (SPOJ MFISH) but I couldn't understand how the DP works. I've seen a few codes online but couldn't comprehend them either. Could someone explain it to me?

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

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

Consider the ships sorted by their anchor index. For every ship you can find a range of indexes where it can start. Just try every possible placement for each ship. The complexity is O(n) because you visit every index at most twice.

P.S.: Thanks to SPOJ, I just found out that there is a programming language called "chicken" :D

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

    OK, got AC. I was using the end location of ships to do my DP, but I think I calculated them wrong. Thanks!