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. ESP8266 nodemcu

    主要资料来源于一下几个网站 1.nodemcu官网:此处有几个示例和github(用处不大) 2.用户说明:http://nodemcu.readthedocs.io/en/master/  (非常重 ...

  2. find实现特殊功能示例

    find列出目录下所有文件: # find /shell-script/ # find /shell-script/ -print find列出文件夹中所有开头为text的文件,参数-iname意思忽 ...

  3. VS2015工具箱不出现ArcGIS Windows Forms怎么办?

    原文: https://blog.csdn.net/pangpi814961437/article/details/7954033

  4. [skill][vim] 常用技巧与配置

    一:  光标行列高亮 可以使用 :help highlight 查看相信帮助可颜色配置. set cursorline set cursorcolumn highlight Cursorline ct ...

  5. 彻底卸载tv

    1.卸载 2.C:\Program Files (x86),找到teamviewer选项,右击删除 3.开始--输入regedit,打开注册表,找到如下路径:HKEY_LOCAL_MACHINE\SO ...

  6. fastreport好象将想合并哪个单元就将那一列的TEXT控件的Merge的属性设成True就可以了

    好象将想合并哪个单元就将那一列的TEXT控件的Merge的属性设成True就可以了 可以用FASTREPORT中的分组打印,你看一下里面的DEMO,里面都有的, 高版本的有suppressRepeat ...

  7. 转:JAVA守护线程

    原文地址:https://www.cnblogs.com/wxgblogs/p/5417503.html 详细内容看原文~  ,写的挺好的 在Java中有两类线程:User Thread(用户线程). ...

  8. Appium环境配置(一)

    一:环境准备(Windows 7版本 64位系统) 1.jdk1.6.0 (64位) 2.android-sdk 3.appium 4.Node.js:node-v8.11.1 5.Appium-Py ...

  9. Orchard Core 增加了一个API模块,要怎么调用

    如下,我在Orchard Core框架中添加了一个API的模块,并且定义了对应的权限才可以调用,那么我们现在考虑的就是要怎么去调用它. 首先,我们用Fiddler查看下我们正常的登录的http报文,直 ...

  10. vim 私人快捷键备忘录

    i 上 k 下 j 左 l 右 ( 上移一段 ) 下移一段 * 搜索关键字 d 删除 y 复制 p 粘贴 h 插入 H 头插 o 下开一行 O 上开一行 f 后跳指定关键字 F 前跳指定关键字 e 字 ...