Light OJ1422 Halloween Costumes

树莓派c语言串口通讯程序 在网上搜了很多关于树莓派串口通讯的例子,但是都是用python写的,虽然python很有名,而且最近也在学习这门语言, 但是还是想用c语言实现一下,因为需要用到整套系统里,其他内容都是用c语言写的。但是网上没有找打现成的。 还好,之前做过天嵌2440开发板的串口程序(参照天嵌工程师提供的代码),发现串口程序其实是通用的, 驱动层屏蔽了硬件细节,个人猜测,几乎所有移植好的系统的串口,都可以用一 阅读详情

题目:

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;
}
【WLAN】【调试】再谈如何使用Wireshark解密WiFi数据包——使用TK信息 - 本文介绍了一种wireshark使用TK信息解密空口报文的方式,该方式对是否有关联过程的报文没有要求。 阅读详情

相关推荐

SigFit实战:从FEA到光学仿真的热力耦合分析全流程解析

在光机系统与芯片封装等精密工程领域,热与力的耦合效应是影响产品性能与可靠性的核心物理问题。有限元分析(FEA)是预测结构在热、力载荷下变形与应力的基础工具,但其结果通常无法直接用于评估光学性能。这需要一座桥梁,将物理场数据转化为光学设计语言。其核心原理在于数据映射与面形表征技术,例如通过泽尼克多项式拟合,将离散的节点位移分解为离焦、像散等标准光学像差。这项技术的工程价值在于,它实现了多物理场仿真的闭环,使工程师能在设计阶段精准预测热变形或应力对波前误差、调制传递函数等关键光学指标的影响。其典型应用场景包括高

weixin_28630185的博客 337

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的博客 378

“华为杯”研究生数学建模竞赛2016年-【华为杯】A题:多无人机协同任务规划

题分别求解,保证了攻击方无人机滞留在防御方雷达有效探测范围内的时间总和最小,接着,通过提出巡检待命无人机的设想,型无人机携带炸弹的具体清单和攻击的目标清单),保证攻击方的无人机滞留防御方雷。在使用基于贪心算法的覆盖法时,覆盖的目标点中必须首先不含配备雷达站的目标点。步优化保证攻击方的无人机滞留防御方雷达有效探测范围内的时间总和最小,需首先。的“灵巧”炸弹,采用抛投方式对地攻击,即投放后炸弹以飞机投弹时的速度作抛物。运动,当炸弹接近目标后,可主动寻的攻击待打击的目标,因此炸弹落点位于目标中。

getusushu的博客 1034

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

VisionPro 机器视觉案例 之 彩色保险丝个数统计

CogColorSegmenterTool CogColorMatchTool

机器视觉李小白的博客 2352

利用autojs制作抢购支付宝消费劵的手机脚本

前期准备工作 1.打开支付宝,点击中间的抢消费券的广告 2.点击左上角,将抢购页面添加到首页 3.查看支付宝首页是否出现消费劵 . autojs代码 "auto"; functiontaskstart(){ sleep(1000); launchApp('支付宝'); toast("正在打开支付宝应用"); sleep(1000); varxf=textContains("消费").findOne().bounds(); ...

洛阳泰山的博客 1万+

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...

菜鸡成长史 194

基于 YOLOv26 的光伏板热斑检测系统:红外+可见光

本文提出了一种基于YOLOv26的光伏板热斑检测系统,采用红外+可见光双模态融合方案。系统架构包含数据预处理、热斑检测、故障诊断和维修决策等模块,结合无人机巡检与地面监控。关键技术包括YOLOv26目标检测模型、双模态数据融合、边缘计算部署等。研究构建了包含多种故障类型的光伏板专业数据集,并采用数据增强技术提升模型性能。系统实现了热斑检测、分类(轻微/中等/严重/危急)以及功率损失评估等功能,为光伏电站智能运维提供解决方案。

一键难忘的博客 497

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

矿石生成(1)

这个提供了标准化的矿石放置配置模板简化了常见和稀有矿石的配置过程遵循了Minecraft原版的世界生成模式提高了代码的可读性和可维护性通过使用这个类,模组开发者可以更轻松地配置矿石的生成规则,而不需要每次都手动编写完整的放置修饰符列表。这种设计模式在原版Minecraft和其他大型模组中也很常见,是一种良好的编程实践。// 导入语句...// 字段和方法...包声明表明这个类位于luckymod模组的WorldGen包中,专门处理世界生成相关配置。导入语句。

qq_24992377的博客 136

Cesium 场景特效之【全球海洋】GL2兼容版

Cesium 场景特效之【全球海洋】GL2兼容版

喜欢钻研前端和分享技术 1278

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的专栏 746

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

【区间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_ 223

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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衣服,...

独钓门前月 418

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的专栏 712

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的博客 107

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 746

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、付费专栏及课程。

余额充值