题目链接 Favorite Color Stripe

题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列

(这个子序列的相邻元素可以重复)

只要求出这个子序列长度的最大值即可

很基础的DP题,设$f[i]$为当前以$a[i]$结尾的子序列的长度的最大值,扫描$B$序列的每个元素时实时更新即可。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int L = 10010;
const int N = 210; int a[L], c[N], f[N];
vector <int> v[N];
int n, m, l;
int ans; int main(){ scanf("%d%d", &n, &m);
rep(i, 1, m){
scanf("%d", c + i);
v[c[i]].push_back(i);
} scanf("%d", &l);
rep(i, 1, l) scanf("%d", a + i); rep(i, 1, l){
for (auto u : v[a[i]]){
if (f[u]) ++f[u];
rep(j, 0, u - 1) f[u] = max(f[u], f[j] + 1); }
} rep(i, 1, m) ans = max(ans, f[i]);
return 0 * printf("%d\n", ans);
}

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

  1. PAT甲级1045. Favorite Color Stripe

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

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

  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][难]

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

  6. PAT甲级——A1045 Favorite Color Stripe

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

  7. 1045 Favorite Color Stripe 动态规划

    1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...

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

    题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...

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

随机推荐

  1. Java代码中的(解压7z加密版)

    maven:需要加上这个下载这两个包 <dependency> <groupId>net.sf.sevenzipjbinding</groupId> <art ...

  2. manjaro18 配置国内镜像源

    1.配置镜像源: sudo pacman-mirrors -i -c China -m rank 2.设置 archlinuxcn 源: sudo nano /etc/pacman.conf 添加以下 ...

  3. nrf51822微信开发入门学习笔记1:开始前的准备

    参考:(id:love--baby)https://blog.csdn.net/hunhun1122/article/details/68922493 微信硬件平台:https://iot.weixi ...

  4. leetcode-7-hashTable

    解题思路: 这道题需要注意的是s和t长度相等,但都为空的情况.只需要扫描一遍s建立字典(char, count),然后扫描t,如果有 未出现的字母,或者键值小于0,就可以返回false了. bool ...

  5. selenium2常用API介绍

    我们模拟web操作都是基于元素来操作的,我们首先要先确定元素,然后这个元素下对应的方法就可以看WebElement的方法. 1.点击操作 WebElement button=driver.findEl ...

  6. 使用docker+tomcat部署jenkins

  7. 模拟 - BZOJ 1510 [POI2006] Kra-The Disks

    BZOJ 1510 [POI2006] Kra-The Disks 描述 Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...

  8. webdriver高级应用- 操作富文本框

    富文本框的技术实现和普通的文本框的定位存在较大的区别,富文本框的常见技术用到了Frame标签,并且在Frame里面实现了一个完整的HTML网页结构,所以使用普通的定位模式将无法直接定位到富文本框对象. ...

  9. linux基础(Vi编辑器)

    整理的linux vi编辑器命令 Vi编辑器,进入方式,输入vi file即可进入编辑模式 1.vi模式(Linux严格区分大小写) Vi所学到的几种模式 模式 主要用途 相应操作 对应命令 普通模式 ...

  10. IO Streams:缓冲流

    我们迄今为止看到的大多数示例都使用无缓冲的I / O.这意味着每个读或写请求都由底层操作系统直接处理.这使程序效率变得很低,因为每个这样的请求经常触发磁盘访问,网络活动或一些相对昂贵的其他操作. 为了 ...