Lightoj 题目1422 - Halloween Costumes(区间DP)
Time Limit: 2 second(s) | Memory Limit: 32 MB |
Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, these parties are all costume parties, Gappu always selects his costumes in such a way that it blends with his friends, that is, when he is attending the party, arranged by his comic-book-fan friends, he will go with the costume of Superman, but when the party is arranged contest-buddies, he would go with the costume of 'Chinese Postman'.
Since he is going to attend a number of parties on the Halloween night, and wear costumes accordingly, he will be changing his costumes a number of times. So, to make things a little easier, he may put on costumes one over another (that is he may wear the uniform for the postman, over the superman costume). Before each party he can take off some of the costumes, or wear a new one. That is, if he is wearing the Postman uniform over the Superman costume, and wants to go to a party in Superman costume, he can take off the Postman uniform, or he can wear a new Superman uniform. But, keep in mind that, Gappu doesn't like to wear dresses without cleaning them first, so, after taking off the Postman uniform, he cannot use that again in the Halloween night, if he needs the Postman costume again, he will have to use a new one. He can take off any number of costumes, and if he takes off k of the costumes, that will be the last k ones (e.g. if he wears costume A before costume B, to take off A, first he has to remove B).
Given the parties and the costumes, find the minimum number of costumes Gappu will need in the Halloween night.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with a line containing an integer N (1 ≤ N ≤ 100) denoting the number of parties. Next line contains N integers, where the ith integer ci (1 ≤ ci ≤ 100) denotes the costume he will be wearing in party i. He will attend party 1 first, then party 2, and so on.
Output
For each case, print the case number and the minimum number of required costumes.
Sample Input |
Output for Sample Input |
2 4 1 2 1 2 7 1 2 1 1 3 2 1 |
Case 1: 3 Case 2: 4 |
#include<stdio.h>
#include<string.h>
#define min(a,b) (a>b?b:a)
int dp[110][110],a[110];
int main()
{
int t,c=0;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i,j,k;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
dp[i][j]=j-i+1;
for(i=n;i>=1;i--)
for(j=i;j<=n;j++)
{
dp[i][j]=dp[i+1][j]+1;
for(k=i+1;k<=j;k++)
{
if(a[i]==a[k])
dp[i][j]=min(dp[i][j],dp[i+1][k-1]+dp[k][j]);
}
}
printf("Case %d: %d\n",++c,dp[1][n]);
}
}
Lightoj 题目1422 - Halloween Costumes(区间DP)的更多相关文章
- LightOJ - 1422 Halloween Costumes —— 区间DP
题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes PDF (English) Statistics F ...
- LightOJ 1422 Halloween Costumes 区间dp
题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...
- light oj 1422 Halloween Costumes (区间dp)
题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...
- Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)
http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html http://www.cnblogs.com/ziyi--caolu/a ...
- 【LightOJ 1422】Halloween Costumes(区间DP)
题 题意 告诉我们每天要穿第几号衣服,规定可以套好多衣服,所以每天可以套上一件新的该号衣服,也可以脱掉一直到该号衣服在最外面.求最少需要几件衣服. 分析 DP,dp[i][j]表示第i天到第j天不脱第 ...
- LightOj 1422 Halloween Costumes(区间DP)
B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOJ - 1422 Halloween Costumes (区间dp)
Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he i ...
- LightOJ 1422 Halloween Costumes 【 区间dp 】
区间dp的第一题----- 看题解看了好多~~终于看懂了---55555 dp[i][j] 表示第i天到第j天至少需要多少件衣服 那么第i件衣服只被第i天占用的话, dp[i][j] = dp[i+1 ...
随机推荐
- HTML meta锚点跳转 小tips
小tips meta锚点跳转 http://www.zhangxinxu.com/wordpress/2015/03/meta-http-equiv-refresh-content/
- PHP require class
- 利用反射调用方法时,处理ref,out参数需要注意的问题(转)
转自:http://www.68idc.cn/help/buildlang/ask/20150318283817.html 项目中如下的泛型方法,因为要在运行时,动态指定类型参数,所以要利用反射来实现 ...
- C# 反射浅析
反射是一个运行库类型发现的过程.通过反射可以得到一个给定程序集所包含的所有类型的列表,这个列表包括给定类型中定义的方法.字段.属性和事件.此外,通过反射也可以动态的发现一组给定类支持的接口.方法的参数 ...
- Emacs下的中文输入
Emacs如此优秀的编辑器,如果输入中文不顺畅,不免遗憾.可惜现实是折腾很久也未必用得称心如意,作为一个重度(也许是中毒) Emacs使用者,根据个人经验写下此文,希望对同道中人有所帮助. 在Wind ...
- 在windows不能正常使用boost og
现象: 1. 在两个不同的dll中使用static的boost.log.在一个dll中的设置在另一个dll中没有起作用 原因:core::get()返回的是一个单例.在不同的dll中是不同的对象 解决 ...
- C# WebForm内置对象2+Repeater的Command
内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及 ...
- 常看常遇见之一——BS架构VS CS架构
常看常遇见之一——BS架构VS CS架构 1.BS架构 即Browser/Server(浏览器/服务器)结构,是随着Internet技术的兴起,对C/S结构的一种变化或者改进的结构.在这种结构下,用户 ...
- JAVA求集合中的组合
好几个月没弄代码了,今天弄个求组合的DEMO 思路是将集合的每个值对照一个索引,索引大小是集合的大小+2.索引默认为[000...000],当组合后选取的组合值demo为[0100..00].然后根据 ...
- PDF 补丁丁 0.5.0.2078 测试版发布:不用打字,也能加书签
新增功能: 在书签编辑器加书签,不再需要自己输文本. 书签编辑器的阅读界面增加了识别文本字符的功能,可使用该功能在添加书签时识别文本. 右键点击文本内容,可插入书签(对于扫描版的文档,在激活识别引擎后 ...