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

Автор Petr, 14 лет назад, По-английски
  • Проголосовать: нравится
  • +105
  • Проголосовать: не нравится

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

Can we submit the problems after the contest ?

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

How to solve B? Especially interesting that "Shanghai Jiao Tong U" has solved it on the 10th minute after the start:

_Problem B: given a sequence of Ws and Ls, find a set of segments of maximum total length such that each segment has more Ws than Ls._

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

    Interesting problem ,anyone know how to solve it ?

    • »
      »
      »
      14 лет назад, скрыть # ^ |
      ← Rev. 6  
      Проголосовать: нравится 0 Проголосовать: не нравится

      EDIT: totally wrong, as shown by reply below. Thanks for the counterexample!

      I haven't tested this yet, but I think it might work. Warning: like most of the algorithms I thought of.. they sounded good in my head, but might turn out to be crap/nonsense in reality, but read on to disprove/ if you think this might inspire a solution.

      From the given example, WLWLLLWWLWLWLLWL,

      create an array that stores the current elevation after reading k characters, where reading a W gives you a +1 elevation, and L a -1 elevation. From the example, we will get [0 1 0 1 0 -1 -2 -1 0 -1 , etc] So now the problem is, find the maximum set of intervals where each interval.endElevation > interval.startElevation

      Then, for each index of the elevation array, find the rightmost index in the elevation array that is greater than elevation[index]. We create an interval object out of this, with start time = index, end time = right most index with elevation > current elevation.

      Now the problem is just interval scheduling, and total runtime is O(n log n).

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

        Interval scheduling maximizes number of tasks, not total duration of them.

        Nevertheless it is not always optimal to find the rightmost index.

        For WLLLWWWLLWLLW optimal solution is W, WWWLLWLLW, not WLLLWWW, W, W

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

    Think how you would solve this using DP in O(n^2) time. Then make it O(n log n) using a tree structure. Maybe there's a greedy that works, but I'm not aware of one.

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

      There are several options how to solve this problem using DP in O(n2).

      For example, state can be:

      • dp[i] — best answer for prefix [0..i] or
      • dp[i][lastsum] — best answer for prefix [0..i] with last segment ending at position i and having sum equal to lastsum.

      What DP-solution do you talk about?

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

    :) 10 minutes is enough to code a dp with fenwich tree

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

I think that D is the similar problem as SPOJ SUBLEX, which is solvable by using a Suffix Automaton.