当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1812:Zuma Game

题目描述
These days Lin falls in love with a PC game called Zuma. In this game, a row of several balls is placed on the table. The color of each ball may be red, yellow, blue, green or white, and we use R, Y, B, G and W to represent these five different colors. There is no group of 3 or more balls of the same color touching at the beginning. The player also has several balls with the color mentioned above in his hand. Every time, the player can choose a ball in his hand, and insert it into the balls on the table at arbitrary position include the left and the right of the row. When there is a group of 3 or more balls in the same color touching, these balls will be moved away. If there are still 3 or more balls in the same color touching, they also should be removed. This operation will be continued until there is no 3 or more balls in the same color touching. If there is no ball on the table after several times of insertion, the player will win. Lin wants to know whether he can win. Can you help him?
输入解释
The first line of the input contains an integer n ( n <= 30 ), which represents the number of test case. Then n cases follow. Each case contains three lines: there are two integer m (1 <= m <=20 ) and k ( 1 <= k <= 5 ) in the first line, and m is the number of balls on the table while k is the number of balls in player's hand; the second line contains m capital letters (there is no space between letters), which represent the color and order of the balls on the table; the third line contains k capital letters, which represent the color of the balls in player's hand.
输出解释
There is a single line for each test case. If the player has no chance to win, output "lose"; otherwise output an integer p, which represents the minimal number of insertion to win the game.
输入样例
3
6 2
WRRBBW
RB
8 4
WWRRBBWW
WWBR
1 2
R
RR
输出样例
lose
2
2

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 POJ Monthly

源链接: POJ-1812

最后修改于 2020-10-29T06:14:46+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000