logo AlgoBeat OnlineJudge
登录 注册

#102220. [BZOJ 2220] CCC2009 Dinner之Zuma2

内存限制:64 MiB 时间限制:10000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: 匿名

题目描述

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

样例

样例输入

7 2
GHHGHHG

样例输出

3

数据范围与提示

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