题目链接 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. for_each_node(node)

    遍历各个pg_data_t节点. 1.定义在include/linux/nodemask.h中 /* * Bitmasks that are kept for all the nodes. */ en ...

  2. hdu 5533

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  4. C语言指针分析

    /*************1*************/ int p; //p是一个普通的整型变量. /*************2*************/ int *p; //p与*结合,说明 ...

  5. 安装好的IIS,发布成功后打开网站出现错误

      开发web项目时需要安装IIS,在安装好IIS的Windows7本上发布asp.net网站时,web程序已经映射到了本地IIS上,但运行如下错误提示“处理程序“PageHandlerFactory ...

  6. Python属性描述符(一)

    描述符是对多个属性运用相同存取逻辑的一种方式,,是实现了特性协议的类,这个协议包括了__get__.__set__和__delete__方法.property类实现了完整的描述符协议.通常,可以只实现 ...

  7. 修改const变量

    看下面的一段代码 ; int * j=(int*)(&i); // 运行正确,j确为i的地址,但 int *j=&i; 编译错误 *j=; //确实改变了i的值 printf(&quo ...

  8. FFT、NTT学习笔记

    参考资料 picks miskcoo menci 胡小兔 unname 自为风月马前卒 上面是FFT的,学完了就来看NTT吧 原根 例题:luogu3803 fft优化后模板 #include < ...

  9. 软件工程师应该关注的web攻击手段

    1.SQL注入------常见的安全性问题. 解决方案:前端页面需要校验用户的输入数据(限制用户输入的类型.范围.格式.长度),不能只靠后端去校验用户数据.一来可以提高后端处理的效率,二来可以提高后端 ...

  10. 【Luogu】P4231三步必杀(差分,差分)

    题目链接 郑重宣布我以后真的再也不会信样例了,三种写法都能过 另:谁评的蓝题难度qwq 蓝题有这么恐怖吗 两次差分,第一次差分,前缀和求出增量数组,第二次求出原数组顺便更新答案 看题解之后……第二次差 ...