智慧屏 安装 app如何提升家庭娱乐与教育体验的关键工具
866
2022-08-29
poj1390 Blocks
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
Source
Liu Rujia@POJ
好难啊qwq icefox好强啊
这题我不看题解感觉根本想不出 膜Icefox巨佬也好久才看懂
首先我先预处理color数组表示把相同颜色的提前都合并起来
然后Len数组表示新的这一组的长度是多少 然后预处理的ava数组 代表我这个之后最多还能有几个连起来的
设dp[i][j][k]表示i~j区间 右端接长度为k的最高得分 当然这k个得和j的颜色相同才可以
dp[i][j][k]=dp[i][j−1][0]+(len[j]+k)2
或者还有一种可能我需要在i~j的区间内找到一个和j相同的 然后消去 dp[i][j][k]=max{dp[i][z][len[j]+k]+dp[z+1][j−1][0]}(z=i−>j−1) 然后转移一下即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~