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

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

Can anyone help me with this problem? http://www.spoj.com/problems/COLORSEG/

It seems it requires some state space reduction/some clever optimisation or an entirely different approach.Have been trying this for quite a long time and no solution/hints are available anywhere.Would be grateful if anyone can help

Теги dp, spoj
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

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

What's wrong with dp(i, c1, c2) equals number of ways to properly assign colors to the first i segments in such a way that i - 2-th segment will receive color c2 and i - 1-th segment — color c1.

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

    Also note that there are t <  = 2500 test cases and time limit is 1 second. Each case runs in O(50 * 50 * 50) = O(1.25 * 1005), so solving all test cases should lead to TLE with that dp recurrence.

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

      There is only 50 different test cases each with his own value of M, but N is meaningless since we can make precalc with N = 50.