1.用一个数组里面存储喜爱数字的值来区分数字是不是喜爱,以及值的大小顺序,用vector循环删除a数组中不是喜爱的元素,这里it=erase()之后it自动指向下一个元素,由于循环每次还要自增1,所以要加上it--。

2.然后就是写dp来寻找最长的序列,序列可以不是连续的,也就是并不是所有的喜爱数字都要选取。

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<int>p(n+, -);
int m;
int i;
scanf("%d", &m);
for (i = ; i < m; i++)
{
int k;
scanf("%d", &k);
p[k] = i;
}
int l;
scanf("%d", &l);
vector<int>a(l, -);
for (i = ; i < l; i++)
{
scanf("%d", &a[i]);
}
vector<int>::iterator it = a.begin();
for (; it != a.end(); it++)
{
if (p[*it]<)
{
it=a.erase(it);//erase()删除的用法.
it--;
}
}
vector<int>dp(a.size(), );
int j;
int ans = -;
for (i = ; i < a.size(); i++)
{
for (j = ; j < i; j++)
{
if (p[a[i]]>=p[a[j]] && dp[j]+>dp[i])
dp[i] = dp[j] + ;
}
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
}

[pat]1045 Favorite Color Stripe的更多相关文章

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

  2. PAT甲级1045. Favorite Color Stripe

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

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

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

  5. 1045 Favorite Color Stripe 动态规划

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

  6. PAT 甲级 1045 Favorite Color Stripe

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

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

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

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

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

随机推荐

  1. FastDFS数据迁移

    参考:https://blog.csdn.net/frvxh/article/details/56293502 FastDFS安装配置参考:https://www.cnblogs.com/minseo ...

  2. Redis 应该是存放的数据超出了范围

    使用ServiceStack操作Redis 发生了 System.StackOverflowException HResult=0x800703E9 Source=<无法计算异常源> St ...

  3. 矩阵游戏|ZJOI2007|BZOJ1059|codevs1433|luoguP1129|二分图匹配|匈牙利算法|Elena

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MB Description 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩 ...

  4. POJ 2449 - Remmarguts' Date - [第k短路模板题][优先队列BFS]

    题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good m ...

  5. tensorRT 使用tensorflow的pb问价构建推理

  6. php源码笔记

    php global 你global了一个变量,那么Zend就会去全局symbol_table去寻找,如果找不到,就会在全局symbol_table中分配相应的变量.通过这样的机制,实现了全局变量. ...

  7. 深入hash

    hash真的很好用,这些杂一点的知识点我觉得还是很有必要的,对还有离散化. 1<=N<=1,000,000,其它所有数据都在[0...1,000,000,000]范围内 看起来很简单一道水 ...

  8. 《mongoDB》查询

    一:简单查询 db.collection.find(query, projection) - query :可选,使用查询操作符指定查询条件 - projection :可选,使用投影操作符指定返回的 ...

  9. idea tomcat控制台system.out.println是乱码

    配置一下tomcat的信息.然后设置VM options.添加:-Dfile.encoding=UTF-8

  10. AT3611 Tree MST 点分治+最小生成树

    正解:点分治+最小生成树 解题报告: 传送门! 然后这题麻油翻译,,,所以这边的建议是先说下题意呢亲 所以题意大概就是说,给一棵n个节点的树,树上每个点都有个权值,然后构造一个完全图,(u,v)之间连 ...