PAT甲级 -1045 Favorite Color Stripe (30 分)

Julia Ann老司机管理系统 https://content.badgirlsusa.com/Julia_Ann-Sexy_Julia_Ann_Fucks_A_Lil_Elf's_Big_Cock_/Julia-Ann-Naughty-America-%E6%80%A7%E6%84%9F%E7%9A%84%E8%A3%98%E8%8E%89%E5%A9%AD%E5%AE%89%E4%BA%82%E6%90%9E-lil-%E7%B2%BE%E9%9D%88%E7%9A%84%E5%A4%A7%E5%85%AC%E9%9B%9E-2020 阅读详情

 

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 that a normal human eye can distinguish about less than 200 different colors, so Eva's favorite colors are limited. However the original stripe could be very long, and Eva would like to have the remaining favorite stripe with the maximum length. So she needs your help to find her the best result.

Note that the solution might not be unique, but you only have to tell her the maximum length. For example, given a stripe of colors {2 2 4 1 5 5 6 3 1 1 5 6}. If Eva's favorite colors are given in her favorite order as {2 3 1 5 6}, then she has 4 possible best solutions {2 2 1 1 1 5 6}, {2 2 1 5 5 5 6}, {2 2 1 5 5 6 6}, and {2 2 3 1 1 5 6}.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (≤200) which is the total number of colors involved (and hence the colors are numbered from 1 to N). Then the next line starts with a positive integer M (≤200) followed by M Eva's favorite color numbers given in her favorite order. Finally the third line starts with a positive integer L (≤10​4​​) which is the length of the given stripe, followed by L colors on the stripe. All the numbers in a line a separated by a space.

Output Specification:

For each test case, simply print in a line the maximum length of Eva's favorite stripe.

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

作者: CHEN, Yue

单位: 浙江大学

时间限制: 400 ms

内存限制: 64 MB

将有序序列,Hash成递增序列,然后对序列进行简化。最后解最大不下降子序列问题。 

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 10010;
const int maxf = 210;
int N, M, L;
int fav[maxf] = { 0 };

int dp[maxn] = { 0 };
int num[maxn];
int A[maxn];
int HashTable[maxf];
int ans = 0;
int main(){
    cin>>N>>M;
    memset(HashTable, -1, sizeof(HashTable));
    for(int i = 0; i < M; i++){
        cin>>fav[i];
        HashTable[fav[i]] = i; 
    }
    cin>>L;
    int num = 0;
    for(int i = 0; i < L; i++){
        int tmp;
        cin>>tmp;
        if(HashTable[tmp] != -1){
            A[num++] = HashTable[tmp];
        }
    }
    for(int i = 0; i < num; i++){
        dp[i] = 1;
        for(int j = 0 ; j < i; j++){
            if(A[i] >= A[j] && dp[i] < dp[j] + 1){
                dp[i] = dp[j] + 1;
            }
        }
        if(dp[i] > ans){
            ans =dp[i];
        }
    }
    cout<<ans;

	return 0;
}

LCS最长公共子序列的解法,没看懂状态转移的方法 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxc = 210;
const int maxn = 10010;
int A[maxc], B[maxn], dp[maxc][maxn];

int main(){
    int n, m, l;
    cin>>n>>m;
    for(int i = 1; i <= m; i++)
        cin>> A[i];
    cin>>l;
    for(int j = 1; j <= l; j++)
        cin>> B[j];
    for(int i = 0; i <=m;i++)
        dp[i][0] = 0;
    for(int j = 0; j <= l;j++)
        dp[0][j] = 0;
    for(int i = 1;  i <= m;i++){
        for(int j = 1; j <= l; j++){
            int MAX = max(dp[i-1][j], dp[i][j-1]);
            if(A[i] == B[j])
            {
                dp[i][j] = MAX + 1;
            }
            else{
                dp[i][j] = MAX;
            }
        }
    }
    cout<<dp[m][l];
    return 0;
    
}

 

一文读懂 SAP ERP / SAP S/4HANA 里的 Price List:概念、配置、定价流程与可运行 ABAP 示例 SAP ERP/S4HANA中的Price List解析 本文系统阐述了SAP定价体系中Price List的核心概念和实现机制。Price List并非独立的价目表,而是通过条件技术(条件类型、访问序列、条件记录)与Price List Type(PLTYP)共同作用的定价维度。文章详细说明了: Price List本质上是客户主数据中的PLTYP字段,作为定价查找键使用 定价流程中条件访问序列如何利用PLTYP查找特定价格 S4HANA与ECC版本在价格维护入口的差异 实际业务中如何通过不同PLTYP实 阅读详情

相关推荐

海康SDK回调PS流解析实战:从字节流到前端H264播放的完整流程

本文详细介绍了海康SDK回调PS流解析的完整流程,从字节流获取到前端H264播放的实现。涵盖SDK初始化、PS流数据结构解析、H264裸流提取、WebSocket传输及前端播放器集成等关键步骤,为视频监控系统开发提供实用指导。

weixin_29061531的博客 204

PAT (Advanced Level) Practice 1045

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

g28_gerwulf的博客 232

交换芯片数据通路四大核心微架构深度解析

数据通路是交换芯片性能的物理根基,决定着低延迟、高吞吐与突发承载能力。其本质是在硅片约束下对带宽、时序、功耗与统计复用的系统性权衡。Crossbar提供确定性低延迟但受RC延迟与功耗制约;VOQ通过虚拟队列隔离输出争抢,却引入仲裁复杂度与内存开销;Shared Buffer依托统计复用提升缓存利用率,但面临碎片化与管理策略挑战;Cell Fabric以固定长度cell重构交换粒度,在AI与金融等小包敏感场景实现尾延迟稳定。这些架构并非替代关系,而是面向不同网络不确定性(如流量不对称性、突发强度、包长分布)的

weixin_32667955的博客 189

PAT甲级题目答案汇总PAT (Advanced Level) Practice (更新中)AcWing

文章目录第一章、字符串处理1001 A+B Format (20 分)1005 Spell It Right (20 分)第二章、高精度1023 Have Fun with Numbers (20 分)第三章、进位制1015 Reversible Primes (20 分)1019 General Palindromic Number (20 分)第四章、排序第五章、树第六章、图论第七章、数学第八章、动态规划第九章、哈希表第十章、并查集第十一章、模拟1008 Elevator (20 分)1011 Worl

m0_51448653的博客 5912

GPS-SDR-SIM使用详解

GPS-SDR-SIM 是一款开源工具,能够生成 GPS 基带信号数据流,这些数据流可通过软件定义无线电(SDR)平台(如 ADALM-Pluto、bladeRF、HackRF、USRP 等)转换为射频(RF)信号。简单来说,它能模拟 GPS 卫星信号,帮助开发者或爱好者测试 GPS 接收设备的性能,而无需依赖真实的卫星信号。

qq_35621280的博客 1241

VisionPro脚本实战:用C#替代QuickBuild,让复杂定位项目代码更清爽

本文探讨了如何通过C#脚本重构VisionPro复杂定位项目,替代臃肿的QuickBuild架构。通过实战案例展示了脚本化开发如何减少60%代码量并提升35%运行效率,使项目更易维护。文章详细介绍了环境搭建、多模板定位重构及高级技巧,帮助开发者突破QuickBuild限制,实现更高效的视觉应用开发。

weixin_30417487的博客 505

A1040 Longest Symmetric String(25分)PAT 甲级(Advanced Level) Practice(C++)满分题解【对称字符串+动态规划】

Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, givenIs PAT&TAP symmetric?, the longest symmetric sub-string iss PAT&TAP s, hence you must output11. Input Specification: Each input file contains o...

qq_47677800的博客 168

使用 Mid360 从零开始搭建实物机器人入门级导航系统 —— 基于 Fast_Lio 和 Move_Base

本文详细介绍了如何使用Mid360机器人从零开始搭建一个基于Fast_Lio和Move_Base的入门级导航系统。通过配置 ROS2、集成激光雷达、IMU、Fast_Lio、Move_Base 等模块,我们成功构建了一个能够实现自动导航的机器人系统。在实际开发中,随着需求的变化,你可以不断调整参数、优化路径规划算法、增加新的传感器等,逐步提升机器人的智能与功能。

小蜗牛的珍贵百宝箱 3567

1045 Favorite Color Stripe (30分)--PAT甲级真题

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

Samson的博客 297

使用Python爬取在线图书馆的图书馆藏和阅读记录

通过使用Python编写爬虫程序,我们可以从在线图书馆上获取图书馆藏和阅读记录,帮助人们更好地管理和利用图书馆资源。本文简要介绍了爬虫程序的准备工作、网页解析和数据提取、数据的保存和处理的关键步骤,并提供了一个示例代码。在实际应用中,我们需要注意遵守在线图书馆的使用规则和爬虫道德准则,确保合法、合规地进行爬取操作。以上仅为概述,实际应用的过程中可能需要根据具体需求进行适当的调整和改进。

2201_76125393的博客 730

Win11此电脑怎么放在桌面上?Win11此电脑如何显示在电脑桌面上?

相信用习惯Win10的用户都喜欢电脑电脑桌面上的此电脑,但是很多用户更新完Win11正式版以后,发现桌面只有回收站和Microsoft Edge图标,没有此电脑。那么,Win11此电脑要如何显示呢?下面小编为大家简单介绍一下操作方法!5、桌面图标设置窗口,点击勾选计算机,然后点击确定,桌面就可以显示此电脑图标了。1、桌面空白处,点击右键,在打开的菜单项中,选择显示设置;4、个性化 - 主题,相关设置下,点击桌面图标设置;3、右侧点击主题(安装、创建、管理);2、设置窗口,左侧点击个性化;

shengyin714959的博客 13万+

【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

Windows 镜像包大全(附百度云下载链接)

插入U盘,找到下载好的两个驱动软件,并安装,先打开驱动人生万能网卡版,安装好网卡驱动,可以接入wifi或者网线了,然后打开驱动精灵,按照提示,安装所有的驱动(中间要是让你重启,就先选择稍后再说,如果有的驱动安装好之后非要你重启,关不掉的那种,那你就重启吧),等全部安装好了,重启电脑。如果你有显卡,这里以英伟达举例,我是GTX960的,当你的驱动都安装好后,右键桌面,会出现一个英伟达控制面板。安装软碟通,下载之后,一直下一步就ok,啥也不用配置,到了最后一项点击“继续试用”即可。(下载里面的网卡版即可),

悦分享 7369

PAT甲级-1045 Favorite Color Stripe (30分)

点击链接PAT甲级-AC全解汇总 题目: 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 sewin...

卷子的博客 541

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

PAT A 甲级 1045 Favorite Color Stripe (30分)

1045 Favorite Color Stripe (30分) 吐槽 说实话用时极限的题在考试的时候都蛮可怕的。毕竟如果不通过基本得从整个思路上大改。不过这题我的代码最后出来的结果蛮让我惊讶的——实际用时都看不出来这是个用时紧张的题了。 思路 如前所述,这是个用时极限的题。关键在于找到一个高效的计算方式。 让我们把题目换一种说法——有一堆数字(节点),有一些后可以跟上另一些(单向桥梁),问一个纳...

虚境的博客 210

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

【PAT甲级】1045 Favorite Color Stripe (30分)

解题过程的小记录,如有错误欢迎指出。 难度:三星(最长递增序列的变形题,最后两个测试点数据量较大,用set会超时,用邻接矩阵可以) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 给出一串数列,要求找出最长的按照指定的增减顺序的子序列 注意点 最后两个测试点的数据量较大,要选择采用省时的方法 我的解题过程 思路 因为本题的总颜色数不超过200个,所以用邻接矩阵pre[i][j]保存颜色i前面可以连着的颜色j,数组类型为bool,当前面可以存在某数时为true 然后就是

SpicyChicken的自我修养 361

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

PAT 甲级 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...

qq_38846633的博客 325

PAT甲级A1045 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...

vir_lee的博客 247

1045 Favorite Color Stripe(30分)-PAT甲级

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

神笔码农.的博客 312

PAT 甲级 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 favorite color stripe. It is

qq_45478482的博客 212

PAT甲级 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 favorite color stripe. It is said

qq_44682929的博客 217

PAT甲级 -- 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...

猪の成长日记 220

PAT甲级1045 Favorite Color Stripe (30 分) 效率最高的动态规划解法

这道题另有DFS、LCS、LIS的解法。这里的解法是动态规划,优点是读一遍输入同时就能处理好,所以非常高效。 核心思想就是【当前】珠子组成手链的最大长度【等于】以这个珠子能接上【以前最长】的某条手链的长度【加一】。 #include<iostream> using namespace std; int n,m,x,maxs,maxp;//默认maxp指的是多个maxs中最大的位置...

qiiingc的解题记录 670

1045 Favorite Color Stripe (30 分)--PAT甲级

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

laplacebh的博客 210

PAT甲级1045 Favorite Color Stripe (30 分)【动态规划LIS】

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

Dexter 232

【PAT 甲级】A1045 Favorite Color Stripe (30分)

思路: 动态规划 时间复杂度: O(ML)O(ML)O(ML) 状态转移方程的求解 设fvrt数组记录颜色序列;strp数组记录纸袋颜色;dp[i]表示以i为结尾的最大长度。 基于此,可对每一个fvrt[j]进行遍历,求得当前的状态转移方程为 dp[i]={dp[i−1]+1,if fvrt[j]=strp[i]max{dp[i−1],dp[i]},if fvrt[j]≠str...

weixin_42278063的博客 199
上一篇: PAT甲级 1007 Maximum Subsequence Sum (25 分)
下一篇: PAT甲级- 1040 Longest Symmetric String (25 分)
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值