[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 ...
随机推荐
- 关于SQL SERVER中的FLOAT转换为VARCHAR
关于SQL SERVER中的FLOAT转换为VARCHAR 一个FLOAT型的字段,要转换为VARCHAR,可是小数点后面的都自动被删去了...后查得可以通过如下转换获得: SELECT CAST(C ...
- SQL Fundamentals: 子查询 || WHERE,HAVING,FROM,SELECT子句中使用子查询,WITH子句
SQL Fundamentals || Oracle SQL语言 子查询(基础) 1.认识子查询 2.WHERE子句中使用子查询 3.在HAVING子句中使用子查询 4.在FROM子句中使用子查询 5 ...
- linux:基本指令touch, cp 和 mv
touch 新建 #touch 的使用很简单, 我们先去往 Documents 的文件夹, 里面已经有了 folder1 和 file1, 如果我们想新建一个 file2 使用下面的语句就好. 一个空 ...
- /etc/apt/sources.list" E212: Can't open file for writing解决方案
:w !sudo tee % > /dev/null 解决.
- haproxy实现会话保持
HAProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.反向代理为什么需要设置cookie 任何一个七层的http负载均衡器,都 ...
- tomcat运行模式
Tomcat Connector的三种不同的运行模式性能相差很大 这三种模式的不同之处如下: BIO: 一个线程处理一个请求.缺点:并发量高时,线程数较多,浪费资源. Tomcat7或以下,在Linu ...
- Xml文件删除节点总是留有空标签
---恢复内容开始--- 在删除Xml文件时,删除成功后还有标签,让我百思不得其解,因为xml文档中留着这空标签会对后续的操作带来很多麻烦,会取出空值,人后导致程序中止. 导致这种情况的原因是删除xm ...
- [development][C] C语言标准
GUN C的标准文档: 也就是glibc https://www.gnu.org/software/libc/ http://man7.org/linux/man-pages/dir_section_ ...
- [troubleshoot][archliunx][chromium][flash] chrome提示flash不是最新
最近chrome总是在提示flash不是最新要求更新. 原来以前用的flash包 chromium-pepper-flash 不见了,改名变成了pepper-flash. /home/tong [to ...
- 【Python全栈-JavaScript】JavaScript入门
JavaScript基础知识点 一.JavaScript概述 参考:http://www.w3school.com.cn/b.asp JavaScript的历史 1.1992年Nombas开发出C-m ...