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

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

I made this problem please try to solve it..

Your comments/solutions will be helpful :D :D

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

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

How many testcases are there?

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

    10

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

      how many times can a city be robbed? once or infinite times?

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

        Sorry,my stupid question.seems to be dynamic programming dp[i][k]=max(dp[s][k-1]+sum_cost[i]-sum_cost[s1]+w*(sum_x[i]-sum_x[s1]) . we can use g[s1][k-1] record max(dp[s][k-1],s<=s1-1) use f[s1][k-1] record max(g[s1][k-1]-sum_cost[s1]-w*sum_x[s1])
        when doing transfer,then transfer is O(1).time complexity is O(n*k)

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

          Could you explain what each of your dp states mean? I'm guessing dp[i][k] is the maximum amount of money we can earn if we teleport to position i and have used k total teleports so far, but am unsure if there are any additional constraints. I'm also not understanding the transition statement.

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

            Yes,we can find we first teleport to a left most position and then walk right,then teleport to a right postion,walk right....

            it is a lot of non intersection segments then dynamic programming works.

            sum_cost[i] infact is sum_profit[i] and sum_x[i] is the position of x,then seems I forgot to minus T[i]..

            for transition: there are two transition point s,s1,s is the right end point of previous segment,and s1 is the left end point of current segment.

            when transition, we can record g[s1][k-1]=max(g[s1-1][k-1],dp[s1][k-1]). then dp function become dp[i][k]=g[s1][k-1]+sum_profit[i]-sum_profit[s1]+w*(sum_x[i]-sum_x[s1])-T[i].

            then we can record f[i][k-1]=max(f[i-1][k-1],g[i][k-1]-sum_profit[i]-w*sum_x[i]).

            then dp[i][k]=f[i-1][k-1]+sum_profit[i]+w*sum_x[i]-T[i].

            seems to be correct..

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

              If I am understanding your transition correctly, you seem to be teleporting into the right endpoint of the current segment, and then walking left until you reach the left endpoint. However, isn't it possible that you will walk right after teleporting? Also, shouldn't it be -w*(sum_x[i]-sum_x[s1])?

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

update: AC now: 12964529 2014-11-24 10:38:10 yangshenThe Hack accepted edit run 0.79 66M C++

btw: you say"teleport that can be used exactly K times before it self-destructs"

I have thought we must use exactly K times teleport,but in fact we can use less than K times. good problem,thank you...

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

I'm approaching the problem by first computing the best cost for each segment. So I have a DP array C[a][b] that gives the profit if we teleport into the segment and visit all banks [a...b] (inclusive). However, I can't find a way to use this with the final DP.

Right now I have DP[x][k] as the max profit if we use banks [0...x] and k segments. Transition is DP[x][k] = max(DP[x-1][k], C[0][x], DP[0][k-1]+C[1][x], DP[1][k-1]+C[2][x], ... DP[x-1][k-1]+C[x][x]) I don't see how we can speed this solution up. Is there a better way to approach this problem? Did I make some false assumptions?

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

I got accepted with a O(N2 * K) solution with some pruning. The pruning is only considering useful segments. A segment [i, j] is useful if there is no other segments [i, k] with k < j whose profit is bigger or equal than that of segment [i, j].

Runtime was horrible (8.53).

How do you make it more efficient than O(N2 * K)?

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

This is the tutorial (written by me as well)..

Please give me your opinions as well, is it well-written?

Or terrible and incomprehensible??