简体   繁体   中英

Dynamic Programming optimal broadcast

I know how to solve this problem in an usual way, not using dynamic programming. If you could be kind enough to explain to me the solution/give me a general idea/ pseudocode. Thanks a bunch.

The input consists of a sequence R = hR0, . . . ,Rni of non-negative integers, and an integer k. The number Ri represents the number of users requesting some particular piece of information at time i (say from a www server).

If the server broadcasts this information at some time t, the the requests of all the users who requested the information strictly before time t are satisfied. The server can broadcast this information at most k times. The goal is to pick the k times to broadcast in order to minimize the total time (over all requests) that requests/users have to wait in order to have their requests satisfied.

As an example, assume that the input was R = 3, 4, 0, 5, 2, 7 (so n = 6) and k = 3. Then one possible solution (there is no claim that this is the optimal solution) would be to broadcast at times 2, 4, and 7 (note that it is obvious that in every optimal schedule that there is a broadcast at time n + 1 if Rn 6= 0). The 3 requests at time 1 would then have to wait 1 time unit. The 4 requests at time 2 would then have to wait 2 time units. The 5 requests at time 4 would then have to wait 3 time units. The 2 requests at time 5 would then have to wait 2 time units. The 7 requests at time 6 would then have to wait 1 time units. Thus the total waiting time for this solution would be 3 × 1 + 4 × 2 + 5 × 3 + 2 × 2 + 7 × 1. .

I/O description. Input: n and k, separated by one space on the first line, then R on second line. Output: the sequence of the k times.

  1. Set the first broadcast at time i.
  2. Solve the problem for R' = {Rj | j>=i} and k' = k-1

Of course, you will need to store all sub-solutions to make it a dynamic programming algorithm rather than plain recursion.

Note that you must begin with k-1 broadcast times, as the kth broadcast will always be after the last time with non-zero users.

The problem is with step 1. You can try every possible position (worst case time complexity will be n*ki think). I recommend you try this naive method first, test it on some data, and see if you can come up with a better way to find the position of the first broadcast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM