#P14732. [ICPC 2022 Seoul R] Shuffle Game
[ICPC 2022 Seoul R] Shuffle Game
题目描述
Shuffle Game is a simple card game between the dealer and the player. Initially, the same deck of cards is given to both the dealer and the player. Each card in the deck suits with one of the four symbols ( or ), followed by the one of 13 kinds ( or ). Therefore, there are 52 different types of cards and the same cards can exist in the deck. After the cards are given to the dealer and the player, the dealer first creates their own deck from the deck given to the dealer using any shuffling method and shows to the player. After that, the player creates the deck by the following steps: is initially empty.
Step 1. Create two decks and from the deck given to the player. The number of cards in and can be different.
Step 2. Interleave and . That is, move a card at the bottom of or to the current top of , until there is no card on both and . Note that the player does not need to move the cards in and alternately to . Also, since both the dealer and the player create their own deck from the same deck of cards, always consists of the same cards as .
We define a sequence of a deck as the sequence of the cards in the deck from bottom to top. Then the player’s score is defined as the length of the longest common subsequence between the sequences and . For example, suppose the deck of cards, is given to both the dealer and the player (here, we represent the deck as its sequence). Then the dealer creates the deck and shows to the player. After that, the player creates their deck by (i) creating two decks and from the given deck and (ii) create by interleaving and . In this example, the player’s score is 3 since is the longest common subsequences between the sequences of and . Now, after finishing Step 1, the player wants to know the maximum possible score that the player can achieve after applying Step 2. For example, the maximum possible score from and in the previous example is 4 since it is possible to create from and as .
Given and , write a program to compute the maximum possible score that the player can achieve.
输入格式
Your program is to read from standard input. The input starts with a line containing three positive integers , and (, ), where is the number of cards in the initial deck, and and are the number of cards in and , respectively. In the following three lines, the dealer’s deck consisting of cards, and the player’s two decks and consisting of and cards, respectively, are given. Each card in , , and is represented as its suit (uppercase alphabet or ) followed by its kind (, uppercase alphabet or ). The cards in the same line are ordered from bottom to top of the corresponding deck.
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain the maximum possible score that the player can achieve from , and after applying Step 2.
5 2 3
CJ D5 HA C2 S7
D5 HA
CJ S7 C2
4
6 3 3
C9 HK SQ SQ H2 CA
CA HK SQ
H2 C9 SQ
4
7 3 4
S9 C10 DJ S6 S7 SA DQ
DJ S6 S7
S9 C10 SA DQ
7