POJ1390Blocks(DP+好题+抽空再来理解理解)
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 4744 | Accepted: 1930 |
Description
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
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
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+好题+抽空再来理解理解)的更多相关文章
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- 贪心/构造/DP 杂题选做Ⅲ
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...
- Vijos1057 盖房子(DP经典题)
之前没有怎么刷过dp的题,所以在此学习了~(感谢walala大神的思路,给了我很大的启发) 也算是自己学习的另一种dp题型吧 先贴上状态转移方程: if(a[i][j]) f[i][j]=min(f[ ...
- dp百题大过关(第一场)
好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem 这 ...
- hdu 2089 不要62 (数位dp基础题)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- DP刷题记录(持续更新)
DP刷题记录 (本文例题目前大多数都选自算法竞赛进阶指南) TYVJ1071 求两个序列的最长公共上升子序列 设\(f_{i,j}\)表示a中的\(1-i\)与b中色\(1-j\)匹配时所能构成的以\ ...
- DP百题练(一)
目录 DP百题练(一) 线性 DP 简述 Arithmetic Progressions [ZJOI2006]物流运输 LG1095 守望者的逃离 LG1103 书本整理 CH5102 移动服务 LG ...
- DP百题练(二)
目录 DP百题练(二) 区间 DP NOI1995 石子合并 IOI1998 Polygon CH5302 金字塔 USACO06FEB Treats for the Cows G/S LG1043 ...
- woj1012 Thingk and Count DP好题
title: woj1012 Thingk and Count DP好题 date: 2020-03-12 categories: acm tags: [acm,dp,woj] 难题,dp好题,几何题 ...
随机推荐
- 商业智能软件对比评测:FineBI和Tableau
FineBI和Tableau是比较好的自助式商业智能软件,功能都很强大,是企业数据可视化不可或缺的利器,但两款产品还是有非常大的区别的,例如Tableau的功能全面且深入,更适合专业的数据分析人员,而 ...
- Android Weekly Notes Issue #229
Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...
- WebViewJavascriptBridge源码探究--看OC和JS交互过程
今天把实现OC代码和JS代码交互的第三方库WebViewJavascriptBridge源码看了下,oc调用js方法我们是知道的,系统提供了stringByEvaluatingJavaScriptFr ...
- iOS 隐藏状态栏
1.整个项目隐藏状态栏 在Targets->General->勾选中Hide status bar . 整个项目隐藏状态栏 2.单个界面隐藏状态栏,例如登录注册页面 1.首先在info.p ...
- iOS 中的 HotFix 方案总结详解
相信HotFix大家应该都很熟悉了,今天主要对于最近调研的一些方案做一些总结.iOS中的HotFix方案大致可以分为四种: WaxPatch(Alibaba) Dynamic Framework(Ap ...
- 整理常用加密 iOS 与 Android 加密 MD5-SHA1
1.MD5算法 不可逆 128位或者64位串,byte数字长度就是16和8,一般表示是使用16进制来表示的话,1个byte转换成2个16bit,分别表示高地位,所以生成的字符串是16位或者是32位的, ...
- centos7中没有安装ifconfig命令的解决方法
初装centos 7时,运行config报 command not found 错误,我在网上找了大量资料,下面的资料中查找原因和解决方式最详细,能很好的解决这个问题. ifconfig命令是设置或显 ...
- 基于easyUI实现组织结构树图形
一. 准备工作 1. 点击此下载相关文件 2. 进入 js 文件夹,解压缩 jquery-easyui-1.5.rar 到当前文件夹 二. 在浏览器中运行 organize.html 文件,即可看到效 ...
- infer 检验IOS项目
1.MAC安装infer: brew install infer 2.设置环境变量指向安装infer/bin下 3.source .bash_profile 4.命令 infer -- xcode ...
- [No00008D]腾讯通RTX联系方式批量获取
公司用的RTX让我一直很不爽,QQ比RTX好多少为啥不让用,微信都有企业版了为啥还用腾讯通?终于今天发现唯一的好处是可以从服务器上拉公司妹子们的联系方式!!当然,我要这些联系方式,只是为了联tiao系 ...