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 ...
随机推荐
- ThinkPHP3.2中if判断条件是两个变量
<select name="typeId"> <foreach name="typeInfo" item="v"> ...
- python GUI输入窗口
为了解决 sublime text 下 python 的 raw_input() 函数无法起效,便萌生了个用 GUI 窗口来获取输入的想法,一开始想用 Tkinter,后来想了下还是用 PyQt 吧, ...
- POJ Challenge消失之物
Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. "要使用剩下的 N - 1 物品装满容积为 x ...
- 分组找ID
select t.name1,t.name2,t.zx from (select row_number()over(partition by name1 order by zx desc)rn, te ...
- 不在折腾----hadoop-2.4.1完全分布式集群搭建
前言 * hadoop2.0已经发布了稳定版本了,增加了很多特性,比如HDFS HA.YARN等.最新的hadoop-2.4.1又增加了YARN HA * 注意:apache提供的hadoop-2.4 ...
- web api+递归树型结构
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...
- android webview远程调试
H5的调试的方式一般用chrome的emulator就好,可是遇到APP就拙计了.这时候还得用远程调试,远程调试很给力,不过目前网上还没有好的文章讲解,要好好的把其配置下来还是非常有难度的,今天折腾了 ...
- MVC3 新建项目
一.安装工具 二.新建项目 step1:新建MVC3项目 打开新建项目窗口,在“已安装的模板”列表中选择“Web”,在右侧应用程序模板列表中选择“ASP.NET MVC3 Web应用程序”,修改项目名 ...
- 原生JS实现购物车功能
html <div class="catbox"> <table id="cartTable"> <thead> <t ...
- 关于nginx反向代理后获取不到客户端的真实ip地址问题
前段时间在我的网站上用nginx做了一下反向代理,最近发现不能获取客户端ip了,都是拿到的127.0.0.1的本地ip... 通过查资料后,再去看了看我的配置文件,结果发现我没有如下配置: nginx ...