Light OJ1422 Halloween Costumes

城市规划师必备:ArcMap里用这个免费工具,5步完成建筑群通风廊道分析 本文介绍了城市规划中利用ArcMap进行建筑群通风廊道分析的高效方法,重点讲解了迎风面投影指数(FAI)的应用。通过5个步骤,从数据准备到规划应用,帮助规划师快速评估城市通风潜力,优化建筑布局,提升城市风环境质量。 阅读详情

题目:

http://www.lightoj.com/volume_showproblem.php?problem=1422

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
2
4
1 2 1 2
7
1 2 1 1 3 2 1

Output for Sample Input
Case 1: 3
Case 2: 4

思路:

题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再用了(可以再穿,但算cost),问至少要带多少条衣服才能参加所有宴会。

dp[i][j]表示i~j所需要的最小数量。
对第j天进行分析:
如果第j天需要穿,那么dp[i][j]=dp[i][j-1]+1;
如果第j天不需要穿,证明在i~j天中存在第k天,使得parties[k]==parties[j],即为穿的衣服相同。
那么dp[i][j]=dp[i][k]+dp[k+1][j-1];

代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[110][110];
int parties[110];
int main()
{
    int ncase,N;
    scanf("%d",&ncase);
    for(int t=1;t<=ncase;t++){
        scanf("%d",&N);
        memset(dp,0,sizeof(dp));
        for(int i=0;i<N;i++){
            scanf("%d",&parties[i]);
        }
        for(int i=0;i<N;i++){
            dp[i][i]=1;
        }
        for(int j=1;j<N;j++){
            for(int i=0;i<j;i++){
                dp[i][j]=dp[i][j-1]+1;
                for(int k=i;k<j;k++){
                    if(parties[j]==parties[k]){
                        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j-1]);
                    }
                }
            }
        }
        printf("Case %d: %d\n",t,dp[0][N-1]);
    }
    return 0;
}
IEC 104电力规约详细解读(一) - 报文结构、报文分类、ASDU 比如,双方可以按频率发送,比如接收8帧I帧回答一帧S帧,也可以要求接收1帧I帧就应答1帧S帧,当然也可以不要求(S帧内容示例参考例1)。所以U帧格式的控制欲第一个字节就只有6种情况,分别是0x83(TESTER确认)、0x43(TESTER命令)、0x23(STOPDT确认)、0x13(STOPDT命令)、0x0B(START确认)、0x07(START命令)ASDU(应用服务数据单元),协议原文格式最好去101协议去看看,会比较详细。遥信、遥测、遥控、遥调、总召、对时等都需要使用I格式传送。 阅读详情

相关推荐

金融波动预测:GARCH模型实战解析与ARIMA对比

本文深入解析GARCH模型在金融波动预测中的实战应用,并与传统ARIMA模型进行对比。通过沪深300指数日收益率数据的案例分析,展示GARCH模型如何有效捕捉波动聚集效应,提升极端波动预测准确率。文章包含Python代码实现、参数解读及模型选择指南,为量化交易者提供实用的波动率建模解决方案。

weixin_29098367的博客 202

LightOJ - 1422

题意:给出每一天需要穿的衣服,衣服外面还可以套衣服,问n天最少需要穿多少次衣服。比如1 2 1,可以第一天穿上1,不要脱掉,第二天穿上2,第三天脱掉2,只需要穿两次。思路:考虑区间dp,dp[i][j]代表从第i天到第j天所需要最少穿衣服次数,枚举断点k,若第i天与第k天所穿的衣服相同,这里就可以考虑重复利用这件衣服,转移方程就是dp[i][j]=min(dp[i][j],dp[i][k-1]+d...

qq_41231363的博客 380

LightGBM处理类别特征和缺失值有多省心?一个真实业务数据案例带你上手

本文通过真实电商数据案例,详细解析了LightGBM如何高效处理类别特征和缺失值。相比传统方法,LightGBM仅需一行代码即可自动处理高基数类别特征和缺失值,大幅提升模型训练效率和预测准确度,特别适合业务场景中的脏数据处理。

weixin_30689307的博客 463

Light OJ 1422 Halloween Costumes(区间DP)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next

Fungyow的博客 1063

基于STM32L4XX、HAL库的 ATGM336H GPS定位模块驱动程序设计

/ 转换为km/h。// 定位状态: 0=无效, 1=GPS定位, 2=差分定位。// GPS解析数据。支持GPS/BeiDou/GLONASS/Galileo/QZSS多系统联合定位。// 回调函数(需要在HAL_UART_RxCpltCallback中调用)// 地面速度(km/h)// 海拔高度(m)

zhusl6688的博客 815

华为OD机试 - 机器人活动区域(Java 双机位C卷 200分)

现有一个机器人,可放置于 M × N的网格中任意位置,每个网格包含一个非负整数编号。之后M行表示网格数值,每行N个数值(数值大小用k表示),数值间用单个空格分隔,行首行尾无多余空格。说明:图中绿色区域,相邻网格差值绝对值都小于等于1,且为最大区域,对应网格点数目为6。M、N、k均为整数,且1

学Java,找哪吒 920

LightOJ - 1422 Halloween Costumes(区间dp)

【题解】 题意:按给定顺序穿衣服去派对,衣服可以叠穿也可以脱下,但是脱下来的衣服不能再穿了。问参加n场派对所需要的最少衣服数目。 思路:若a[i]=a[j],说明穿上a[i]然后叠穿再脱可以继续穿着a[i]去派对j,那么dp[i][j]=min(dp[i][j-1]);否则dp[i][j]=dp[i][j-1]+1。 【代码】 #include <cstdio> #inclu...

菜鸡成长史 195

交货单冲销发货过账的正确姿势:用 VL09 与 ABAP 批量反冲 Goods Issue

摘要 本文详细解析了SAP系统中VL09事务码的技术实现与业务应用。VL09用于反冲发货的货物移动,通过标准冲销路径(移动类型602冲销601)确保单据链路一致、状态机正确回退和业务规则生效。文章对比了经典VL09与Fiori应用在不同SAP产品形态中的位置,并针对STO场景提供了ME23N验证方法。核心内容包括WS_REVERSE_GOODS_ISSUE函数模块的调用要点、必须COMMIT的原因(SAP LUW机制),以及处理Handling Unit等限制条件的注意事项。最后给出了将VL09工程化的项目

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 622

Light oj 1422 Halloween Costumes(区间DP:迭代or记忆化搜索)

题目:1422 - Halloween Costumes 题意: 有n个party要参加,每次参加必须穿固定的衣服(ci),每次参加可以选择穿衣服或者脱衣服,也就是可以用外面的衣服将里面的衣服覆盖,后面需要就脱掉外面的把需要的衣服露出来,给出n次party要穿的衣服编号,求最少花费多少衣服 分析: 区间DP dp[i][j]表示从第i个party到第j个party所需的最少服装数 if

Must so 363

PCL点云库入门(第6讲)——PCL库中Eigen数学工具库的基本使用(持续更新)

Eigen库是一个高性能的C++模板库,专注于线性代数、矩阵和向量运算,以及相关的数值分析和算法。在Eigen库中,所有的矩阵和向量均被视为矩阵模板类的实例。向量可以被看作是特殊形式的矩阵,具体表现为只包含1行或1列。

qq_36812406的博客 1758

让 ABAP 开发更聪明的搭档:SAP Joule for Developers 与 ABAP AI Capabilities 全面实战

摘要:SAP已将生成式AI集成到ABAP开发工具中,推出Joule for Developers功能。该功能直接嵌入Eclipse开发环境,提供代码解释、生成、测试构造和遗留代码迁移等辅助功能。Joule支持ABAP Cloud项目开发,能围绕当前开发对象提供上下文相关的建议,帮助开发者高效完成应用开发与迁移任务。启用该功能需升级ADT并获取相应许可,典型应用场景包括RAP应用构建和S/4HANA迁移中的代码重构。官方资源提供了多个实践案例,帮助开发者快速上手这一AI辅助开发功能。(149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 510

Light oj 1422 Halloween Costumes

区间DP #include #include #include #include using namespace std; #define INF 999999 typedef long long ll; int const MAXN = 110; int dp[MAXN][MAXN],c[MAXN]; inline int Min(int a,int b){ retur

z8853797的专栏 748

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

【区间DP】Light OJ 1422 - Halloween Costumes

Light OJ 1422 - Halloween Costumes 当a[st] == a[ed]时,非常容易知道完全可以把中间的衣服脱掉只剩最里面那一件,所以容易得到dp[st][ed] = dp[st][ed - 1] 否则,就还是采用枚举断点的方式,等于小区间相加也就是dp[st][ed] = dp[st][mid] + dp[mid + 1][ed] something: ...

L_X_ 225

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

light oj 1422 - Halloween Costumes (区间dp)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next

To be what you what to be! 2311

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Light oj 1422 - Halloween Costumes

题目:http://lightoj.com/volume_showproblem.php?problem=1422 #include #include using namespace std; int c[105]; int dp[105][105]; int main () { int T, N; scanf("%d", &T);

AcIsFun的博客 362

Light OJ 1422 Halloween Costumes (区间DP)

1422 - Halloween Costumes     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, n

jncsw的博客 390

Light oj 1422-Halloween Costumes 【区间DP】

小灰灰参加圣诞节的一些派对,并且需要穿上对应派对的衣服,所以他需要多次换衣服,为了方便,他可以选择脱掉一些衣服或者穿上新衣服,比如说,他穿着超人的衣服,外面又穿着死侍的衣服,当他要参加超人服装派对时,他可以选择脱掉死侍的衣服(因为死侍衣服的里面有超人的衣服),或者他可以在穿一件超人的衣服,小灰灰是个爱干净的人,当他脱下死侍的衣服后,如果需要再穿死侍的衣服,他会选择再穿一件新的。(如果他先穿A衣服,...

独钓门前月 421

light oj 1422 Halloween Costumes (区间DP)

题意: 。。。 思路: 跟着kuangbin的blog开始刷区间DP。。 开始也是对这道题没想法。。 不对,联系了一下 hdu 2476 String painter 这道题。。 发现思考模式是一样的。。 dp[i][j]dp[i][j] 照例是区间 i,j 的最小代价 考虑从 dp[i+1][j]dp[i+1][j] 转移过来 费用就是 i 与 i+1 穿的衣服是否相同 dp[

slowlight93的专栏 714

Light OJ 1422 Halloween Costumes(区间DP)

http://lightoj.com/volume_showproblem.php?problem=1422. 题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再用了(可以再穿),问至少要带多少条衣服才能参加所有宴会。   dp[i][j]表示i到j区间的最小穿衣数量。然后我们通过扫描i到j之间的k点来更新dp[i][j]。当c[k]与c[j]为相同衣服时,那么显然有d

ACMiao的博客 441

Light OJ 1422 - Halloween Costumes

题目链接:http://lightoj.com/volume_showproblem.php?problem=1422 很简单的区间DP的入门题。一开始这题想了很久就是想不出来。直到做了后面几道区间DP回过来终于想明白了。 区间DP可以使用记忆化搜索和直接DP的方法写。 这题的状态转移方程: dp[i][j]=min(1+dp[i+1][j],dp[i+1][k-1]+dp[k][j]) ...

weixin_34067980的博客 108

Light OJ 1422 Halloween Costumes

传送门 Halloween Costumes                     Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Appoint description: Description Gappu has a very busy weeken...

weixin_34356310的博客 199

Light oj 1422 Halloween Costumes(区间 dp)

//终于A了区间dp的第二道题 //这道题说难也算难解题报告都看不懂把我想的头疼 说简单想清楚了也真简单 //题意: 有n个宴会需要参加每个宴会要穿指定的衣服 这个人可以问最少穿多少件 //思路: dp[i][j]表示参加i到j宴会需要穿衣服的最少件数  // 从后往前dp // 如果穿上第i件衣服则dp[i][j]=dp[i+1][j]+1; // 但是可能i到j中存在第k个宴会 使

supper__fool 766

【DP】 Light OJ 1422 Halloween Costumes

地址:点击打开链接 对于每个区间 #include #include #include #include #include #include #include #include using namespace std; #include #include #include #include #include #define cler(arr, val) mems

Kewowlo 748

light oj 1422 Halloween Costumes (区间DP)

题意:这里有 n 个变装晚会,有一个人要穿这着衣服去参加晚会,已知,这个人在这 n 个舞会中要穿几号衣服,求这个人在参加完这个舞会,最少需要多少套衣服。 但是一件衣服如果脱了,就不能再使用,如果还需要这个编号的衣服,就只有使用一套新衣服。 这个人在参加舞会的时候,只需要最外面那件衣服是该编号就可以,里面可以穿很多衣服。 区间DP: 令 dp[i][j], 是完成i 到 j 区间的最

swust_Three的博客 435
上一篇: 2015年第六届蓝桥杯省赛
下一篇: Cocos2d-x的坐标系
_IanXiao
博客等级 码龄12年 84粉丝 241原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址