Description
Some of you may have played a game called ‘Blocks’. There are n blocks in a row, each box has a color. Here is an example: Gold, Silver, Silver, Silver, Silver, Bronze, Bronze, Bronze, Gold.
The corresponding picture will be as shown below:
![]()
Figure 1
If some adjacent boxes are all of the same color, and both the box to its left(if it exists) and its right(if it exists) are of some other color, we call it a ‘box segment’. There are 4 box segments. That is: gold, silver, bronze, gold. There are 1, 4, 3, 1 box(es) in the segments respectively.
Every time, you can click a box, then the whole segment containing that box DISAPPEARS. If that segment is composed of k boxes, you will get k*k points. for example, if you click on a silver box, the silver segment disappears, you got 4*4=16 points.
Now let’s look at the picture below:
![]()
Figure 2
The first one is OPTIMAL.
Find the highest score you can get, given an initial state of this game.
Input
The first line contains the number of tests t(1<=t<=15). Each case contains two lines. The first line contains an integer n(1<=n<=200), the number of boxes. The second line contains n integers, representing the colors of each box. The integers are in the range 1~n.
Output
For each test case, print the case number and the highest possible score.
Sample Input
2
9
1 2 2 2 2 3 3 3 1
1
1
Sample Output
Case 1: 29
Case 2: 1
题目大意
给定n个不同颜色的盒子,连续的相同颜色的k个盒子可以拿走,权值为k*k,求把所有盒子拿完的最大权值。
题解
合并初始相邻相同的块,得到颜色数组c和对应的长度len.
例如 1 1 1 1 1 3 2 2 1 1 1 可记为color[1]=1; len[1]=5; color[2]

该博客介绍了一个名为'Blocks'的游戏,玩家需要消除相同颜色相邻的方块并根据消除的方块数获得分数。给定游戏的初始状态,目标是找到可能获得的最高分数。博主提供了输入输出样例,并解释了题意,接着详细阐述了解题思路,包括如何合并初始颜色块,以及使用动态规划求解最大得分的策略。
最低0.47元/天 解锁文章
609

被折叠的 条评论
为什么被折叠?



