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. dts中memreserve和reserved-memory的区别 (转)

    https://blog.csdn.net/kickxxx/article/details/54631535

  2. WPF 打开指定文件路径的文件资源管理器

    x 需求是想让WPF打开一个指定文件路径的文件夹,但是搜出来的八成都是<打开文件>的这样的↓ Microsoft.Win32.OpenFileDialog open_file = new ...

  3. tensorflow如何正确加载预训练词向量

    使用预训练词向量和随机初始化词向量的差异还是挺大的,现在说一说我使用预训练词向量的流程. 一.构建本语料的词汇表,作为我的基础词汇 二.遍历该词汇表,从预训练词向量中提取出该词对应的词向量 三.初始化 ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 I. Lattice's basics in digital electronics 阅读题加模拟题

    题意:https://nanti.jisuanke.com/t/31450 题解:题目很长的模拟,有点uva的感觉 分成四步 part1 16进制转为二进制string 用bitset的to_stri ...

  5. git commit -m 与 git commit -am的区别

    字面解释的话,git commit -m用于提交暂存区的文件:git commit -am用于提交跟踪过的文件 要理解它们的区别,首先要明白git的文件状态变化周期,如下图所示 工作目录下面的所有文件 ...

  6. winform excel导入--自带office.interop.excel方式

    用npoi方式,遇到一个问题,有的excel用加密软件(盖章,只读等)生成的解析不了,所以换成自带的方式,可以解决. 需要引用系统自带Microsoft.office.interop.excel pu ...

  7. kubenets installation--ranchor-mesos

    [kube-proxy]http://www.cnblogs.com/xuxinkun/p/5799986.html [flannel] 安装Flannel [root@master ~]# cd ~ ...

  8. 解决双系统(Window10+Ubuntu16.10)下ubuntu安装git时提示软件包git没有可安装候选问题

    选择升级系统: sudo apt-get update 升级之后再输入: sudo apt-get install git 可成功安装.

  9. 机器学习技术点----apachecn的github地址

    预处理 离散化 等值分箱 等量分箱 独热 one-hot 标准化 最小最大 min-max z-score l2 标准化 归一化 特征选择 ANOVA 信息增益/信息增益率 模型验证 评价指标 回归 ...

  10. Nand Flash 驱动框架

    框架入口源文件:s3c_nand.c (可根据入口源文件,再按着框架到内核走一遍) 内核版本:linux_2.6.22.6   硬件平台:JZ2440 以下是驱动框架: 以下是驱动代码 s3c_nan ...