Blocks
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 4744   Accepted: 1930

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
题意:通过点击某一颜色消除相邻的所有的这种颜色,得分为len*len,求最大分;
http://wenku.baidu.com/view/d956d2f30b4c2e3f5627630b分析:当看代码的时候却觉着原来就是这么简单
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std;
struct box_segment
{
int color,len;
};
box_segment segment[];
int score[][][];
int click_score(int start,int End,int extra_len)
{
if(score[start][End][extra_len] > )
return score[start][End][extra_len];
int result;
result = segment[End].len + extra_len;
result = result * result;
if(start == End)
{
score[start][End][extra_len] = result;
return score[start][End][extra_len];
}
result += click_score(start, End - , );
for(int i = End - ; i >= start; i--)
{
if(segment[i].color != segment[End].color)
continue;
int temp = click_score(start, i, segment[End].len + extra_len) + click_score(i + , End - ,);
if(temp <= result)
continue;
result = temp;
break;
}
score[start][End][extra_len] = result;
return score[start][End][extra_len];
}
int main()
{
int t,n,End;
int num = ;
scanf("%d", &t);
while(t--)
{
End = ;
scanf("%d", &n);
scanf("%d", &segment[End].color);
segment[End].len = ;
for(int i = ; i < n; i ++)
{
int color;
scanf("%d", &color);
if(color == segment[End].color)
segment[End].len++;
else
{
segment[++End].color = color;
segment[End].len = ;
}
}
memset(score, , sizeof(score));
printf("Case %d: %d\n", ++num,click_score(, End, ));
}
return ;
}

POJ1390Blocks(DP+好题+抽空再来理解理解)的更多相关文章

  1. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  2. 贪心/构造/DP 杂题选做Ⅲ

    颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...

  3. Vijos1057 盖房子(DP经典题)

    之前没有怎么刷过dp的题,所以在此学习了~(感谢walala大神的思路,给了我很大的启发) 也算是自己学习的另一种dp题型吧 先贴上状态转移方程: if(a[i][j]) f[i][j]=min(f[ ...

  4. dp百题大过关(第一场)

    好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem    这 ...

  5. hdu 2089 不要62 (数位dp基础题)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. DP刷题记录(持续更新)

    DP刷题记录 (本文例题目前大多数都选自算法竞赛进阶指南) TYVJ1071 求两个序列的最长公共上升子序列 设\(f_{i,j}\)表示a中的\(1-i\)与b中色\(1-j\)匹配时所能构成的以\ ...

  7. DP百题练(一)

    目录 DP百题练(一) 线性 DP 简述 Arithmetic Progressions [ZJOI2006]物流运输 LG1095 守望者的逃离 LG1103 书本整理 CH5102 移动服务 LG ...

  8. DP百题练(二)

    目录 DP百题练(二) 区间 DP NOI1995 石子合并 IOI1998 Polygon CH5302 金字塔 USACO06FEB Treats for the Cows G/S LG1043 ...

  9. woj1012 Thingk and Count DP好题

    title: woj1012 Thingk and Count DP好题 date: 2020-03-12 categories: acm tags: [acm,dp,woj] 难题,dp好题,几何题 ...

随机推荐

  1. HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本 ,请添加处理程序。如果下载文件,请添加 MIME 映射。 IIS站点中添加WCF项目后浏览网站报错解决方法。

    vs2013 wcf服务 windows10 家庭中文版 上图中的红色没有出现就按照下面的方法做: 按照上图所示勾选. 刷新上图中你的网站,查看上图右边的内容是否出现,如果出现,再次重新浏览网站,看一 ...

  2. iOS提交AppStore后申请加急审核

    提交审核后进去下面链接申请加急审核链接:https://developer.apple.com/appstore/contact/appreviewteam/index.html 在I would l ...

  3. ArrayList、Vector、LinkedList的区别联系?

    1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...

  4. 软件工程第二次作业——git的使用

    1. 参照 http://www.cnblogs.com/xinz/p/3803109.html 的第一题,每人建立一个GitHub账号,组长建立一个Project,将本组成员纳入此Porject中的 ...

  5. [Bind(Exclude = "OrderId")][ScaffoldColumn(false)]

    [Bind(Exclude = "OrderId")] 的意思是:View里的Model,在你提交给 Action时,不会绑定到Action的参数Model,默认它会绑定. mvc ...

  6. 自动分割mp3等音频视频文件的脚本

    由于种种关系,我需要对一批mp3文件进行分割(切割).每个音频文件大约1小时,需要切成每10分钟1个文件,文件名要带序号.手工分割工作量太大,不符合我等“懒人”的做法.于是找到了大名的”格式工厂“. ...

  7. Rocksdb Compaction原理

    概述 compaction主要包括两类:将内存中imutable 转储到磁盘上sst的过程称之为flush或者minor compaction:磁盘上的sst文件从低层向高层转储的过程称之为compa ...

  8. ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法

    远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...

  9. Ubuntu 下ibus拼音输入法启用 (ubuntu 16.04

    Ubuntu 下ibus拼音输入法启用 我安装的是英文版的ubuntu 16.04,打开只带英文,并没有中文. 设置输入法为iBus 从system settings 进入language suppo ...

  10. css3 text-overflow和white-space,word-wrap,word-break进阶

    一.text-overflow 1.text-overflow作用 简单来说,text-overflow用来设置文本溢出时是否用省略标记(...) 准确的说是设置溢出的文本在不显示的情况下怎样展示给用 ...