2220 - CCC2009 Dinner之Zuma2

类似于zuma游戏,给定一排N个珠子,已知每个珠子的颜色(原题中颜色只有2种),以及一个整数K。问你最少进行多少次操作,可以把这些珠子全部消去。每次操作是:选择连续的一段,它们必须是包含同一种颜色,并且长度不小于K,将它们消去,左右两边的合并。(不会自动消去,产生链式反应。)如果不能完成,输出-1即可。数据规模:N不超过100,K不超过6。

输入

输出

样例

输入

7 2
GHHGHHG

输出

3

提示

First send the? rst pair of Hs to dinner,leaving GGHHG.Thens end the second pair of Hs to dinner,leaving GGG;?nally,send inthe group of Gs.It might be coincidental that the two pairs of Help?le programmers entered the cafeteria successively.

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题