#P1541. [NOIP 2010 提高组] 乌龟棋

    ID: 532 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2010递归NOIp 提高组枚举,暴力

[NOIP 2010 提高组] 乌龟棋

Description

On Xiaoming’s birthday, his father gave him a Turtle Chess set as a gift.

The Turtle Chess board is a row of NN cells, each with a score (a non-negative integer). Cell 11 is the only starting point, and cell NN is the end. The player controls a turtle piece to move from the start to the end.

There are MM crawling cards in Turtle Chess, divided into 44 different types (the MM cards do not necessarily include all 44 types; see the sample). Each type of card is labeled with one of the numbers 1,2,3,41,2,3,4, meaning that after using such a card, the turtle moves forward by the corresponding number of cells. In the game, each time the player must choose one crawling card that has not been used before from all cards, and move the turtle forward accordingly. Each card can be used only once.

In the game, the turtle automatically gains the score of the starting cell, and during subsequent moves, whenever it arrives at a cell, it gains that cell’s score. The final score is the sum of the scores of all cells the turtle visits from start to end.

Clearly, different orders of using the crawling cards can lead to different final scores. Xiaoming wants to find an order that maximizes the final score.

Given the score of each board cell and all the crawling cards, can you tell Xiaoming the maximum score he can obtain?

Input Format

Numbers on each line are separated by a single space.

The first line contains two positive integers N,MN,M, the number of board cells and the number of crawling cards.

The second line contains NN non-negative integers, a1,a2,,aNa_1,a_2,…,a_N, where aia_i is the score on cell ii.

The third line contains MM integers, b1,b2,,bMb_1,b_2,…,b_M, which are the numbers on the MM crawling cards.

The input guarantees that upon reaching the end, exactly all MM crawling cards have been used.

Output Format

Output one integer, the maximum score Xiaoming can obtain.

9 5
6 10 14 2 8 8 18 5 17
1 3 1 2 1

73

Hint

Each test point: 1 s.

Xiaoming uses the crawling cards in the order 1,1,3,1,21,1,3,1,2, and the score is 6+10+14+8+18+17=736+10+14+8+18+17=73. Note that since the start is 11, he automatically gains the score 66 on cell 11.

Constraints: For 30%30\% of the testdata, 1N30,1M121 \le N \le 30,1 \le M \le 12. For 50%50\% of the testdata, 1N120,1M501 \le N \le 120,1 \le M \le 50, and among the 44 types of crawling cards, the count of each type does not exceed 2020. For 100%100\% of the testdata, 1N350,1M1201 \le N \le 350,1 \le M \le 120, and among the 44 types of crawling cards, the count of each type does not exceed 4040;$0 \le a_i \le 100(1 \le i \le N),1 \le b_i \le 4(1 \le i\le M)$。

Translated by ChatGPT 5