2089. min Strokes

单点时限: 2.0 sec

内存限制: 256 MB

Karel is a frustrated painter who works by day in an electrical repair shop. Inspired by the color-coded bands on resistors, he is painting a series of long, narrow canvases with bold colored stripes. However, Karel is lazy and wants to minimize the number of brush strokes it takes to paint each canvas.

Abbreviating each color to a single uppercase letter, Karel would write the stripe pattern red-green-blue-green-red as “RGBGR” (quotes added for clarity). It would take him three brush strokes to paint this pattern. The first stroke would cover the entire canvas in red (RRRRR). The second stroke would leave a band of red on either side and fill in the rest with green (RGGGR). The final brush stroke would fill in the blue stripe in the center (RGBGR).


There are many test cases.Each line giving a stripe pattern stripes as a String.

-stripes will contain only uppercase letters (‘A’-‘Z’, inclusive).

-stripes will contain between 1 and 50 characters, inclusive.


calculate and output the minimum number of brush strokes required to paint that pattern.


This example cannot be done in two strokes, even though there are only two colors. Suppose you tried to paint both red stripes in one stroke, followed by both green stripes in one stroke. Then the green stroke would cover up the second red stripe. If you tried to paint both green stripes first, followed the red stripes, then the red stroke would cover up the first green stripe.

2 人解决,6 人已尝试。

4 份提交通过,共有 32 份提交。

9.4 EMB 奖励。

创建: 11 年,2 月前.

修改: 2 年,5 月前.

最后提交: 9 年,2 月前.

来源: TC