[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 ...
随机推荐
- ERP项目实施记录06
自上月20以后,因厂里赶货,办公室人员有空也要去车间帮手,ERP的事就没动静了. 2014年1月10日开了个小组会议,认为第三方不是专业做本行业的,开发风险大:因此希望先开发一个报价软件试试. 明天第 ...
- Mac上的jdk
最近装jdk从网上找到的资料: 一.以前版本的Mac自带了的JDK6,安装在目录:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/下.* JDK7 ...
- Arrays 类的一些常见用法
package cn.ljs; import java.util.Arrays; public class ArrayDemo { public static void main(String [] ...
- Luogu 3369 / BZOJ 3224 - 普通平衡树 - [无旋Treap]
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...
- CH 1602 - The XOR Largest Pair - [字典树变形]
题目链接:传送门 描述在给定的 $N$ 个整数 $A_1, A_2,\cdots,A_N$ 中选出两个进行xor运算,得到的结果最大是多少? 输入格式第一行一个整数 $N$,第二行 $N$ 个整数 $ ...
- tensorflow的assgin方法
官网API是这么说的 This operation outputs a Tensor that holds the new value of 'ref' after the value has bee ...
- win10环境下搭建zookeeper伪集群
一.下载zookeeper https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 这里笔者下载的是zookeeper-3.3.6 二.配置zoo ...
- day6:前两小节补充
1,练习题一:以66分割,大于部分一个键值对,小于部分一个键值对 li = [23,78,67,45,34,89,67,78,23,23] lig = [] lil = [] dic = {} for ...
- [daily][archlinux] 本地字符乱码, 无法显示中文
一: 突然有一天,Konsole里边看见的中文文件名的文件,就变成了乱码.thunderbird存到本地的附件,文件名也变成了乱码. 在X下查看locale,内容如下: 手动设置了之后也不对. 但是在 ...
- LeetCode 917 Reverse Only Letters 解题报告
题目要求 Given a string S, return the "reversed" string where all characters that are not a le ...