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 ...
随机推荐
- Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison
Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in compa ...
- JQuery_元素样式操作
元素样式操作包括了直接设置CSS 样式.增加CSS 类别.类别切换.删除类别这几种操作方法.而在整个jQuery 使用频率上来看,CSS 样式的操作也是极高的,所以需要重点掌握. 一.css()方法 ...
- unity自带寻路Navmesh入门教程(二)
上一节简单介绍了NavMesh寻路的基本用法,这次来介绍一下稍微复杂一点点的高低落差以及跳跃的做法,首先来看看这次的目标: 由于博客相册上传GIF有限制,所以我把整个过程切开了2部分上传,第一部分 ...
- fiddler 命令
Fiddler内置的命令有如下几种: 1. select命令. 选择所有相应类型(指content-type)为指定类型的HTTP请求,如选择图片,使用命令select image.而select c ...
- 【xsy1629】可持久化序列 - 可持久化平衡树
题意 你现在要用数据结构维护一个长度为n的序列. 这个序列支持三种操作: 1 l r:将序列中的第l项到第r项这一段翻转. 2 l r:查询序列中[l,r]这一段的和. 3 p:回到第p个历史版本. ...
- Asp.net项目路径获取方法【转】
获取项目完整的绝对路径string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString();string path = Serve ...
- 拆分SharePoint 2013 中CreatedModifiedInfo 的时间
最近在自定义DisForm.aspx页面时 发现 创建时间信息无法进行拆分,人事MM只想要修改时间,去掉创建人,创建时间和修改人. 于是我的重新研究下在SPD里面如何去拆分这个时间. 在详情页面上找到 ...
- ASP.NET MVC简介
MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码 ...
- 查看APK中MD5签名的方法
(需下载jdk) 1. 先将apk文件重命名为zip文件 2. 解压zip,其中的META-INF/CERT.RSA文件即MD5签名文件 3. cmd下打开黑窗口,敲入如下命令: keytool -p ...
- 关于nginx反向代理后获取不到客户端的真实ip地址问题
前段时间在我的网站上用nginx做了一下反向代理,最近发现不能获取客户端ip了,都是拿到的127.0.0.1的本地ip... 通过查资料后,再去看了看我的配置文件,结果发现我没有如下配置: nginx ...