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好题,几何题 ...
随机推荐
- Android 使用pull,sax解析xml
pull解析xml文件 1.获得XmlpullParser类的引用 这里有两种方法 //解析器工厂 XmlPullParserFactory factory=XmlPullParserFactory. ...
- Android中使用GridView和ImageViewSwitcher实现电子相册简单功能
我们在手机上查看相册时,首先看到的是网格状的图片展示界面,然后我们选择想要欣赏的照片点击进入,这样就可以全屏观看该照片,并且可以通过左右滑动来切换照片.如下图的显示效果: 首先我们先罗列一下本次实现所 ...
- android Animation介绍
Animation介绍: 在Android SDK介绍了2种Animation模式: 1. Tween Animation:间动画,通过对场景里的对象不断做图像变换(平移.缩放.旋转)产生动画效果,即 ...
- gulp入门小记
由于我所在的项目组一直在用gulp构建工具,而我只是在前人搭好的环境下每次运行gulp packJs来打包js,对里面的东西全然不知,刚好最近有些时间就想自己从学学将gulp怎么用于构建前端项目中,这 ...
- T-SQL 查询XML
我们经常在SQL Server列中存一些XML来作为配置文件或者是保存特殊信息,那么如何将其展开并查询它或将其呈现为关系数据? 其实在T-SQL 下可以很容易的实现. 示例xml <catalo ...
- ubuntu关于引导修复[grub命令行][live linux]
第一种:grub命令行: ls 列出所有分区 ls /grub ls /grub 检查确认linux引导分区,如果linux单独/boot分区,就要采用如下命令进行检查: ls /boot/grub ...
- Fragment之间传值
Activity: String myArguments; public String getarguments() { return myArguments; } public void ...
- 关闭selinux
1.查看SELinux状态:getenforce Enforcing(启动) disable(禁用) 1.禁用SELinux(重启后依然生效) 修改 vi /etc/sysconfig/selinux ...
- 【FLUENT案例】05:DDPM模型
本例利用FLUENT的DDPM模型对提升管进行模拟. 1 介绍 本案例演示在FLUENT中利用稠密离散相模型(Dense discrete phase model,DDPM)模拟2D提升管.DDPM模 ...
- Microsoft SQL Server 2008 R2 安装卸载
问题 问题1 标题: Microsoft SQL Server 2008 R2 安装程序 ------------------------------ 出现以下错误: Could not open k ...