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

建议使用的浏览器:

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

3059:Rummikub

题目描述
Rummikub is a simple game, often played by elderly people versus their grandchildren. It is a tile-based game and each of the tiles has a colored number written on it. There are four available colors: yellow, red, green and black. A tile is described by its number followed by a lower case letter, which is the first letter of its color. All tiles are unique.

The goal of game is simple: get rid of all your tiles. This sounds easier than it is, since you can only use them in two specific ways. You can get rid of tiles by constructing runs or groups. A run is composed of three or more consecutive numbers of the same color, for example 9r, 10r, 11r, or 6g, 61g, 62g, 63g, 64g, 65g. A group is composed of three or four tiles with the same numbers, and therefore different colors. Examples are 1r, 1g, 1b and 17r, 17g, 17b, 17y. In constructing the runs and groups, you may only use each tile once.

The value of a run or group is the sum of the numbers on the tiles. Your score is the sum of the values of all the runs and groups you construct. What is your maximum possible score?
输入解释
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
One line with one integer N, satisfying 1 <= N <= 400: the number of tiles you have.
One line with N strings separated by single spaces, each consisting of a number between 1 and 100 and a character which is either 'y', 'r', 'g', 'b': the available tiles. All tiles are unique.
输出解释
For every test case in the input, the output should contain a single number, on a single line: the maximum possible score.
输入样例
3
5
7g 7b 7r 8r 9r
7
23b 1y 24b 1r 93b 1b 100r
8
2y 2r 2g 2b 4g 5g 6g 7g
输出样例
24
3
30

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

源链接: POJ-3059

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

共提交 0

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