题意:

输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个正整数L(<=10000),代表条带的长度,接着输入L个正整数表示条带上的颜色的编号。输出以喜爱颜色顺序排列的最长子串长度(不必每种颜色都有,只保证相对位置相同,同种颜色可连续)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[],pos[];
int dp[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int color;
for(int i=;i<=m;++i){
cin>>color;
pos[color]=i;//记录颜色的相对位置
}
int cnt=;
int stripe;
int l;
cin>>l;
for(int i=;i<=l;++i){
cin>>stripe;
if(pos[stripe])
a[++cnt]=pos[stripe],dp[cnt]=;//记录条带上颜色在喜爱条带上的位置
}
int mx=;
for(int i=;i<=cnt;++i){
for(int j=;j<i;++j)//以相对位置j结尾的都可以在后面加上以相对位置i结尾的颜色
if(a[j]<=a[i])
dp[i]=max(dp[i],dp[j]+);//更新以相对位置i结尾的子串的长度
mx=max(mx,dp[i]);//选取最长长度作为答案
}
cout<<mx;
return ;
}

【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)的更多相关文章

  1. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  2. PAT甲级1045. Favorite Color Stripe

    PAT甲级1045. Favorite Color Stripe 题意: 伊娃正在试图让自己的颜色条纹从一个给定的.她希望通过剪掉那些不必要的部分,将其余的部分缝合在一起,形成她最喜欢的颜色条纹,以保 ...

  3. pat 甲级 1045 ( Favorite Color Stripe ) (动态规划 )

    1045 Favorite Color Stripe (30 分) Eva is trying to make her own color stripe out of a given one. She ...

  4. PAT 甲级 1045 Favorite Color Stripe

    https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...

  5. PAT 甲级 1045 Favorite Color Stripe(DP)

    题目链接 Favorite Color Stripe 题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列 (这个子序列的相邻元素可以重复) ...

  6. 1045 Favorite Color Stripe (30分)(简单dp)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  7. PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***

    1068 Find More Coins (30 分)   Eva loves to collect coins from all over the universe, including some ...

  8. 1045 Favorite Color Stripe (30)(30 分)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  9. 1045. Favorite Color Stripe (30) -LCS允许元素重复

    题目如下: Eva is trying to make her own color stripe out of a given one. She would like to keep only her ...

随机推荐

  1. 【NS-3学习】ns3-模拟基础:关键概念,日志,命令行参数

    前言 本篇博客先介绍在仿真过程中会使用到的一些关键概念,然后介绍便于调试仿真脚本的常用技术:日志.命令行参数. 关键概念 节点 在因特网术语中,主机(终端)是指任何一台连接到网络的计算设备.ns-3并 ...

  2. 解决用 VB 中用 ADO 访问 数据库时 SQL 查询处理 Null 值的问题( 使用 iff(isNull(字段), 为空时的值,不为空时的值) 来处理)

    程序的环境是 VB6 + ADO + Access,在用 SQL 语句查询时,希望把两个字段合并成一个字段,但其中一个字段 Null 值直接导致两个字段合并后也变成了 Null 值.之前只能用 VB ...

  3. python正则非贪婪模式

    上一篇python正则匹配次数大家应该也发现了,除了?其他匹配次数规则都是尽可能多的匹配 那如果只想匹配1次怎么办呢,这就是正则中非贪婪模式的概念了 原理就是利用?与其他匹配次数规则进行组合 单个匹配 ...

  4. 【原】shell增加定时任务

    通过shell脚本增加定时任务:#CRON_FILE="/var/spool/cron/root" (centos系统) CRON_FILE="/var/spool/cr ...

  5. PHP通过thrift2访问HBASE

    前一段时间需要在网页上显示HBASE查询的结果,考虑用PHP来实现,在网上搜了一下,普遍都是用thrift作为接口来实现的.​ 参考博文:​ http://www.cnblogs.com/scotom ...

  6. 【C语言】将两个字符串连接起来

    #include<stdio.h> int main() { ] = "I "; ] = "am a student"; int i, j, n; ...

  7. TCL Strings

    append    Append values to variable binary      Insert and extract fields from binary strings regexp ...

  8. linux 下部署web 程序

    linux 下部署web 程序 1. 创建ucenter用户 一般情况下,发布应用程序都不是使用root用户的,需要创建一个普通用户来发布程序: 创建ucenter用户: useradd -d /uc ...

  9. 唠唠C++二级指针、二维数组、指针数组、数组指针等的区分

    今天看c++primer第六章,有这部分的内容,脑子有点糊涂了,看了几篇博客,自己敲了下,记录一下备忘. 二级指针: int **p; 二维数组: int p[10][10]; char q[10][ ...

  10. 攻防世界 你知道php备份文件吗?

    题目地址:https://adworld.xctf.org.cn/task/answer?type=web&number=3&grade=0&id=5064 php的备份有两种 ...