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

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

Plz help me in solving this problem?

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

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

link to problem?

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

It's a greedy and brute force problem.

For any given message order, process the packets greedily. You should repeat the following process for each packet.

  • 1) Add the packet to the buffer.
  • 2) As long as the packet you should output next is stored in the buffer, output it and remove it from the buffer.
  • 3) Check the size of the buffer.

The minimum needed buffer size for the message order will be the maximum among all the buffer sizes at Step 3.

Since N ≤ 5, you can try out all possible orderings of the messages. Every packet will be added only once to the buffer and removed only once, so the process is linear for each ordering, hence the total complexity will be O(M * N!).