[pat]1045 Favorite Color Stripe
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的更多相关文章
- 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. ...
- PAT甲级1045. Favorite Color Stripe
PAT甲级1045. Favorite Color Stripe 题意: 伊娃正在试图让自己的颜色条纹从一个给定的.她希望通过剪掉那些不必要的部分,将其余的部分缝合在一起,形成她最喜欢的颜色条纹,以保 ...
- 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 ...
- 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 ...
- 1045 Favorite Color Stripe 动态规划
1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...
- PAT 甲级 1045 Favorite Color Stripe
https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...
- PAT 甲级 1045 Favorite Color Stripe(DP)
题目链接 Favorite Color Stripe 题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列 (这个子序列的相邻元素可以重复) ...
- 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 ...
- 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 ...
随机推荐
- [No0000167]CPU内部组成结构及指令执行过程
计算机的基本硬件系统由运算器.控制器.存储器和输入.输出设备五大部件组成.运算器和控制器等部件被集成在一起统称为中央处理单元(Central Processing Unit,CPU). CPU的功能 ...
- linux 背单词
命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户rpm:redhat package manager 红帽子打包管 ...
- 字母算术的python算法
据说Google出过一道题目:WWWDOT – GOOGLE = DOTCOM. 其中每个字母代表一个数字,数字不能重复,而且最高位的数字不能为0. 像这样的谜题被称为cryptarithms或者字母 ...
- pgadmin4 python
安装安装包 # sudo apt-get install build-essential libssl-dev libffi-dev libgmp3-dev virtualenv python-pip ...
- vmware为我们提供了三种网络工作模式,它们分别是:Bridged(桥接模式)、NAT(网络地址转换模式)、Host-Only(仅主机模式)。
原文来自http://note.youdao.com/share/web/file.html?id=236896997b6ffbaa8e0d92eacd13abbf&type=note 我怕链 ...
- [https][ssl] keyless SSL
HTTP Server 集群前的负载设备,或内容审计设备等,在处理https的时候,需要用户配置提供证书. 但是考虑到安全问题,HTTP Server并不愿意把证书配置到其他设备上. 这个时候,就有个 ...
- [daily][cgroup] 使用cgroup限制进程的CPU占用
参考: https://segmentfault.com/a/1190000008323952 1. 找到cgroup设置的地方. [root@D128 ~]# mount -l |grep cpu ...
- [administrative][lvm] lvm 分区修改
默认安装的CentOS6.3操作系统,使用lvm分区.root挂载了50G,home挂载了1.5T. 由于需求要求,现在需要把home的1.5T全部移动到root下. 使用archiso启动,查看lv ...
- HashMap如何做循环遍历
1.TestCase:
- 关于javascript中defineProperty的学习
语法 Object.defineProperty(obj, prop, descriptor) 参数 obj 要在其上定义属性的对象. prop 要定义或修改的属性的名称. descriptor 将被 ...