A1045 Favorite Color Stripe (30) 动态规划

PAT甲级 1045 Favorite Color Stripe Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.It is said t 阅读详情

本题注意的点是可能出现不需要的颜色,提前就应该剔去这个点,也可以使这个点的值最大,这样也能将它并入其中。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10010;
int d[maxn]={0},a[maxn],index[maxn]={0};
int main()
{
	int n,m,k,ans=-1,temp,num=1;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&temp);
		index[temp]=i;
	}
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&a[num]);
		if(index[a[num]]==0)
		{
			continue;
		}
		else
		{
		     num++;
		}
	}
	for(int i=1;i<num;i++)
	{
		d[i]=1;
	    for(int j=1;j<i;j++)
	    {
	    	if(index[a[i]]>=index[a[j]]&&(d[j]+1)>d[i])
	    	   d[i]=d[j]+1;
		}
		ans=max(ans,d[i]);
	}
	printf("%d",ans);
}


手把手教你调试eDP接口:Main Link信号异常、AUXCH通信失败怎么办? 本文提供了一份详尽的eDP接口调试实战指南,重点解决Main Link信号异常与AUXCH通信失败两大核心难题。文章系统介绍了从工具准备、信号完整性分析(眼图、抖动测量)到AUXCH协议解码、HPD信号检查的完整排查流程,并分享了链路训练诊断与常见避坑技巧,帮助硬件工程师高效定位并解决显示问题。 阅读详情

相关推荐

深度学习十大算法之Word2Vec

Word2Vec的提出,标志着词嵌入技术的一次重大进步。Word2Vec是一种高效的词嵌入模型,由Google的研究团队于2013年开发。它使用一种称为神经网络的机器学习方法,通过学习大量文本数据,生成能够表达词语间丰富语义关系的词向量。Word2Vec的核心优势在于它能够捕捉到词语之间的细微关系。例如,在Word2Vec模型中,可以通过计算向量之间的距离来估计词语之间的相似度。这不仅能帮助理解语言的复杂性,还可以应用于各种NLP任务,如机器翻译和搜索引擎优化。

第欧根尼的酒桶的博客 1865

1045 Favorite Color Stripe (30 分)

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...

SourDumplings的博客 406

2026最新 OpenClaw 手机端部署与实战:旧手机秒变 AI 智能终端(Android/iOS 双平台全覆盖)

OpenClaw 是2026年 GitHub 爆火的开源自托管 AI 执行网关,前身是 Clawdbot / Moltbot,主打“一句话让 AI 帮你完成真实操作”,核心能力包括发消息、整理文件、控制设备、自动化任务等,区别于普通对话式 AI,它能将 AI 指令转化为实际行动。无需高配置设备,无需专业技术,旧手机就能变身随身 AI 助手,既能实现自动化办公、生活便捷,又能保障数据隐私,还能体验极客玩法,这正是开源技术的魅力。# 初始化配置(按提示操作,配置 AI 模型 API Key)

wohaiweifaju的博客 5647

【PAT甲级】1045 Favorite Color Stripe(30 分)(LCS转化为LIS)

题目链接 Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining...

feng_zhiyu的博客 567

别再为淘宝滑块发愁了!一个Python脚本自动获取x5sec cookie的保姆级教程

本文提供了一套完整的Python自动化解决方案,帮助开发者轻松应对淘宝滑块验证码问题。通过模拟浏览器行为、精准识别滑块缺口位置和生成拟人化移动轨迹,脚本能够自动获取关键的x5sec cookie,显著提升爬虫效率。教程涵盖环境配置、验证机制分析、代码实现及反检测策略,是解决淘宝滑块验证的实用指南。

weixin_30300225的博客 575

DaVinci Developer和DaVinci Configurator:AutoSAR开发与配置工具

a. 组件创建:DaVinci Developer允许开发人员创建不同类型的AutoSAR软件组件,如应用软件组件(Application Software Component,SWC)、基础软件组件(Basic Software Component,BSWC)等。除了以上功能,DaVinci Developer和DaVinci Configurator还提供了丰富的文档和代码生成功能,以支持开发人员和配置人员进行文档编写、代码生成和文档浏览等任务。用户可以根据具体需求对软件组件进行灵活的配置。

HmoaAmp的博客 2262

PAT A1045 Favorite Color Stripe (30 分) 动态规划

DFS有两个测试点超时,看来只能用动态规划做了,待补。 DFS代码: #include <vector> #include <cstdio> using namespace std; void dfs(vector<int> &v, int i, vector<int> &ret, int &maxSize) { ...

HackingGate的博客 316

YOLOv11改进 | Conv改进篇 | 含2种改进,引入DynamicConv替换普通Conv卷积下采样和C3k2_DynamicConv替换C3k2(来自CVPR2024)

本文提出了一种基于DynamicConv动态卷积优化的YOLOv11轻量化模型改进方案。通过引入多专家机制的动态卷积模块,在增加模型参数量的同时保持较低的计算复杂度(FLOPs),有效解决了低FLOPs模型在大规模预训练中的性能瓶颈问题。文章详细介绍了动态卷积的工作原理、核心代码实现,并提供了在YOLOv11中集成DynamicConv和C3k2_GhostModule_DynamicConv模块的完整教程,包括模块添加、配置文件修改和模型训练验证过程。实验结果表明,该方案在保持高效推理速度的同时显著提升了

Ai缝合怪、助力小伙伴高效发论文 537

pat甲级 动态规划 A1045 Favorite Color Stripe (30分)

1045 Favorite Color Stripe (30分) Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her

weixin_42358356的博客 166

WinCC实现定时存储数据至SQLServer

环境 Win10 WinCC V7.5 SQL Server 2016 运行结果 流程 WinCC变量 全局VB脚本 (我设置的是每2秒存一次,因此周期性触发器设置1秒)

skr? 3988

知识图谱(Knowledge Graph)原理与代码实战案例讲解

知识图谱(Knowledge Graph)原理与代码实战案例讲解 作者:禅与计算机程序设计艺术 / Zen and the Art of Computer Programming 1. 背景介绍 1.1 问题的由来

AI天才研究院 1078

PAT-A-1045 Favorite Color Stripe (30 分) 动态规划--最长非降子序列 C++题解

1045 Favorite Color Stripe (30 分) 题目传送门:1045 Favorite Color Stripe (30 分) 一、题目大意 给定数组1、数组2,求数组2的最长的符合数组1中元素顺序的子序列。 For example, given a stripe of colors {2 2 4 1 5 5 6 3 1 1 5 6}. If Eva’s favorite c...

爱玲姐姐的博客 1004

【ARM CoreLink 系列 7 -- TZC-400控制器简介】

为了确保内存能够正确识别总线的信号控制位,新增一个TrustZone地址空间控制器(TrustZone Address Space Controller,TZASC)组件来实现对内存地址的安全扩展,将内存区域划分为安全内存区域和非安全内存区域,安全世界可以访问安全内存和非安全内存,而普通世界只能访问非安全内存,如下图所示:图 1-1内存区域的划分是在系统启动时通过配置 TZASC 组件(TZC-400/TZC-380)来实现的。TZC-400由和使能情况;安全访问权限;Base地址;

CodingCos的博客 1634

A1045 Favorite Color Stripe (30 分| 动态规划| LIS| LCS,附详细注释,逻辑分析)

写在前面 思路分析 给出m中颜色作为喜欢色(给出顺序),然后给出1串长度为L的颜色序列,现在要去掉这个序列中不喜欢的颜色,然后求剩下序列的1个子序列,使得这个子序列表示的颜色顺序符合自己喜欢的颜色顺序,不1定所有喜欢颜色都出现。 分析: 喜欢颜色是不重复,把喜欢颜色的序列依次存储到数组中, book[i] = j表示i颜色的下标为j。 先在输入的时候剔除不在喜欢的序列中的元素,然后把剩余的保...

kngines 340

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【PAT】A1045 Favorite Color Stripe (30分)(动态规划初级--两种方法LIS和LCS做)

1045 Favorite Color Stripe (30分) 题目链接 思路一: #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int maxn = 10004; int order[maxn];//喜欢的序列 int strip...

醉酒诗人的博客 235

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

PAT (Advanced Level) Practice A1045 Favorite Color Stripe (30 分)(C++)(甲级)(动态规划)(两种方法)

原题链接:A1045 Favorite Color Stripe #include&amp;amp;lt;algorithm&amp;amp;gt; #include&amp;amp;lt;iostream&amp;amp;gt; #include&amp;amp;lt;cstdio&amp;amp;gt; #include&amp;amp;lt;cstring&amp;amp;gt; #include &amp;amp;lt

izhxxx的博客 201

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PAT A1045 Favorite Color Stripe (30)----动态规划之LCS变种经典题目

  1.LCS版:代码: 分析:(上边串为a,下边为b) 6 5 2 3 1 5 6 12 2 2 4 1 5 5 6 3 1 1 5 6 由题目可知:b串肯定会有重复元素,a串可能有;不同于常规的LCS没有重复元素 关键就是递推关系怎么推? 1.当a[i]和b[j]不相等的时候: 好好想想:当不相等的时候,递推公式不会变,因为不可能有两个最后一个元素诶!关键就是相等的时候怎么办呢...

luoshiyong123的博客 269

pat甲级 A1045 Favorite Color Stripe (30分)

题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 题目分析: 此题有点类似求解两个最长公共子串。()

dutmathjc的博客 296

PAT 1045. Favorite Color Stripe

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1045 题解: DP。转换成求最长递增子序列。 代码: #include #include #include #include #include #include #include #include #include #include using namespace std; int dp[

Ted's 游乐园 1694

动态规划:PAT 1045 Favorite Color Stripe

ADS的第7周作业,是一个动态规划算法题。问题重现Title: Favorite Color StripeDescription:Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by

1837

1045. Favorite Color Stripe (30)

1. 原题: https://www.patest.cn/contests/pat-a-practise/1045 2. 思路: 题意: 给定一个子串及总串,求总串最长的子串序列(可重复及不连续)。 思路: 算法逻辑题。核心思想是动态规划(全局最优必定包含某个局部最优)。 这是LCS(最长公共序列不连续)的变形。该题允许重复。 动态规划关键是写出状态及状态转移方程。 分析: 设喜

坚不萌 282

PAT 甲级 1045  Favorite Color Stripe

1045 Favorite Color Stripe (30 point(s)) Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwa...

漫浸天空的雨色的备忘录~ 933

[C++] PAT 1045 Favorite Color Stripe (30分)

Sample Input: 6 5 2 3 1 5 6 12 2 2 4 1 5 5 6 3 1 1 5 6 Sample Output: 7 题解: 该题运用动态规划,使用最长增长子序列(LIS)思想,在更新dp数组时需要判断当前颜色 i 和 i之前的颜色j,满足c_order[i] >= c_order[j]以及dp[j]+1 > dp[i],再更新dp[i] #include <iostream> using namespace std; int n,m,l; i.

快乐de约定的博客 2070

A1045 Favorite Color Stripe (30分)

#include<cstdio> #include<stdlib.h> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<set> #include<vector> #include<map> #include<queue> #include<stack> #in.

Liberalspirit的博客 222

1045 Favorite Color Stripe (30分)

题目 Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining pa...

小白的博客 526

1045 Favorite Color Stripe

1045 Favorite Color Stripe (30 分) Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pi...

qq_41698081的博客 254
上一篇: A1007 Maximum Subsequence Sum (25) 动态规划
下一篇: A1040 Longest Symmetric String (25) 动态规划
coder_Kim
博客等级 码龄8年 2粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值