C. New Year Book Reading(CF)模拟

New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He hasnbooks numbered by integers from 1 ton. The weight of thei-th (1≤i≤n) book iswi.

As Jaehyun’s house is not large enough to have a bookshelf, he keeps thenbooks by stacking them vertically. When he wants to read a certain bookx, he follows the steps described below.

Heliftsall the books above bookx.He pushes bookxout of the stack.He puts down the lifted books without changing their order.After reading bookx, he puts bookxon the top of the stack.

He decided to read books formdays. In thej-th (1≤j≤m) day, he will read the book that is numbered with integerbj(1≤bj≤n). To read the book, he has to use the process described in the paragraph above. It is possible that he decides to re-read the same book several times.

After making this plan, he realized that the total weight of books he shouldliftduringmdays would be too heavy. So, he decided to change the order of the stacked books before the New Year comes, and minimize the total weight. You may assume that books can be stacked in any possible order. Note that book that he is going to read on certain step isn’t considered asliftedon that step. Can you help him?

,只有不快的斧,没有劈不开的柴。

C. New Year Book Reading(CF)模拟

相关文章:

你感兴趣的文章:

标签云: