题意:告诉有n场晚会中需要穿的衣服,衣服是可以套在其他衣服外面的,
也就是说如果顺序为 1 2 1,那么可以将2套在1外面,第三场晚会需要穿1的时候把2脱掉即可,这样就只需要穿两次衣服。
题目是再告诉了顺序之后需要求出在某种序列下最少需要穿多少次衣服。

思路:区间DP,对于区间【i,j】,如果a[i]在[i+1,j]中未出现,dp[i][j] = dp[i+1][j]+1,否则a[i]应考虑是否被重复利用,若重复利用那么并不需要再一次穿上a[i],所以dp[i][j] = min(dp[i][j],dp[i][k-1],dp[k+1][j])。

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <queue>
#include <algorithm>
#define MAXSIZE 1005
#define LL long long
#define INF 0x3f3f3f
#define mod 10056 using namespace std; int dp[MAXSIZE][MAXSIZE],a[MAXSIZE]; int Solve(int n)
{
for(int i=;i<MAXSIZE;i++)
{
for(int j=i;j<MAXSIZE;j++)
{
dp[i][j] = j-i+;
}
} for(int i=n;i>=;i--)
{
for(int j=i+;j<=n;j++)
{
dp[i][j] = dp[i+][j] + ;
for(int k=i+;k<=j;k++)
{
if(a[k] == a[i])
{
dp[i][j] = min(dp[i][k-]+dp[k+][j],dp[i][j]);
}
}
}
}
return dp[][n];
} int main()
{
int T,n,cns=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int ans = Solve(n);
printf("Case %d: %d\n",cns++,ans);
}
return ;
}

light oj 1422 - Halloween Costumes的更多相关文章

  1. dp之区间:Light oj 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多 ...

  2. light oj 1422 Halloween Costumes (区间dp)

    题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...

  3. Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)

    http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html http://www.cnblogs.com/ziyi--caolu/a ...

  4. Lightoj 题目1422 - Halloween Costumes(区间DP)

    1422 - Halloween Costumes   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. LightOJ - 1422 Halloween Costumes —— 区间DP

    题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes    PDF (English) Statistics F ...

  6. LightOj 1422 Halloween Costumes(区间DP)

    B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...

  7. LightOJ - 1422 Halloween Costumes (区间dp)

    Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he i ...

  8. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  9. LightOJ 1422 Halloween Costumes 区间dp

    题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...

随机推荐

  1. ASCLL、Unicode和UTF-8编码的理解

    我们已经讲过了,字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit) ...

  2. str

    print('字符串操作') s='abc DEF hij' print('首字母大写') print(s.capitalize()) print('全大写') print(s.upper()) pr ...

  3. JS_一些小方法总结

    1.js中onclick事件同时调用两个方法 用分号隔开即可,比如 <input type="button" onclick="a();b();" val ...

  4. 【C#】C#创建自定义Object对象

    艹,老是忘!!! }; 记录一下,var obj = new { Name="lily",Age=12};

  5. Spring Boot笔记九:AOP面向切面编程

    我参考的这篇文章,以验证身份为例讲解了什么是AOP AOP 这里只讲解一下怎么去实现AOP 新建一个类,叫HttpAspect用来切面 package com.vae.springboot.study ...

  6. freemarker写入word【未完,待续】

    . java基于feemarker 生成word文档

  7. 高性能的代理服务-Envoy

    Envoy最初建于Lyft,是一个高性能的代理服务,为服务网格提供了基础. 它与应用程序并行运行,通过以平台无关的方式提供通用功能来抽象网络. 当基础架构中的所有服务流量都通过Envoy网格时,通过一 ...

  8. Kettle系列:Pentaho DI (Kettle) 下载地址

    Kettle 8 已经发布, 下载地址还不太好找, 这里记录一下: 注: 所有大型软件升级都需要谨慎,  尤其是大版本的第一个小版本都不推荐在生产环境使用. github 总是有最新版 https:/ ...

  9. JS创建对象之构造函数模式

    function Person(name, age, job) { this.name = name; this.age = age; this.job = job; this.sayName = f ...

  10. JQuery Rest客户端库

    JQuery Rest https://github.com/jpillora/jquery.rest/ Summary A jQuery plugin for easy consumption of ...