#P4290. [HAOI2008] 玩具取名

    ID: 3225 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2008河南各省省选枚举,暴力区间 dp概率论,统计

[HAOI2008] 玩具取名

Description

Someone has a set of toys and wants to give them names. First, he chooses any one letter from W, I, N, G as the base name of a toy. Then, according to his preference, he can replace any letter in the current name with any allowed pair of letters from W, I, N, G, so that the name can grow very long.

Now, given a very long name, he wants you to guess which initial letters it could have been derived from.

Input Format

The first line contains four integers W,I,N,GW, I, N, G, indicating how many different pairs of letters each letter can be replaced by.

The next WW lines each contain two letters, indicating that W can be replaced by these two letters.

The next II lines each contain two letters, indicating that I can be replaced by these two letters.

The next NN lines each contain two letters, indicating that N can be replaced by these two letters.

The next GG lines each contain two letters, indicating that `G$ can be replaced by these two letters.

The last line contains a string of length LL, representing the toy’s name.

Output Format

Output a single line string listing the letters from which the given name could have been derived (in the order W, I, N, G). If the given name cannot be derived from any letter, output The name is wrong!.

1 1 1 1
II
WW
WW
IG
IIII

IN

Hint

Constraints

  • 30%30\% of the testdata satisfies L20L \leq 20, W,I,N,G6W, I, N, G \leq 6.
  • 100%100\% of the testdata satisfies L200L \leq 200, W,I,N,G16W, I, N, G \leq 16.

Translated by ChatGPT 5