| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 512 MB | 0 | 0 | 0 | 0.000% |
You are playing a game with a stack of N disks (1 ≤ N ≤ 100). The goal of the game is remove all of the disks from your stack. However, there is a cost associated with removing disks, and you wish to minimize the cost of removing all the disks from your stack.
Each disk contains a label, with the label L being in the range 1 ≤ L ≤ 20.
You are also given a “Master stack” of N disks which you can use to help you remove disks from your stack.
You can remove disks from the top of your stack of disks in two ways:
You are also allowed to modify the order of the top K (1 ≤ K ≤ 4) elements of your stack, so long as immediately after each modification, you remove the top element of your stack. There are three allowed modifications:
If the operations yield a match between the top of the master stack and the top of your stack, you can pop for free. If not, you must pay the cost of the pop.
There is one additional constraint. At any point in the game, if a disk at level j is being popped (levels start at 0 at the bottom of the stack), then all elements that were originally at level j + M or higher must have already been popped, where 1 ≤ M ≤ 5.
Minimize the cost required to pop all the elements off of your stack.
The first line will contain 6 space-separated integers: N, K, M, D, U, R where:
2N lines will follow, each containing a number L (1 ≤ L ≤ 20). The first N lines will contain the labels of the disks in the Master stack, from top to bottom. The next N lines will contain the labels of the disks in your stack, from top to bottom
Output the integer (on one line) which is the minimal cost required to remove all disks from your stack.
7 3 3 4 4 3 5 6 3 4 1 2 3 5 6 5 1 4 1
5
We take 3 to the bottom and shift the two blocks below it up, with cost 4. Then we remove four blocks from each stack, remove a 1 from the playing stack, with cost 1, and remove two blocks from each stack.