1.用一个数组里面存储喜爱数字的值来区分数字是不是喜爱,以及值的大小顺序,用vector循环删除a数组中不是喜爱的元素,这里it=erase()之后it自动指向下一个元素,由于循环每次还要自增1,所以要加上it--。

2.然后就是写dp来寻找最长的序列,序列可以不是连续的,也就是并不是所有的喜爱数字都要选取。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. scanf("%d", &n);
  7. vector<int>p(n+, -);
  8. int m;
  9. int i;
  10. scanf("%d", &m);
  11. for (i = ; i < m; i++)
  12. {
  13. int k;
  14. scanf("%d", &k);
  15. p[k] = i;
  16. }
  17. int l;
  18. scanf("%d", &l);
  19. vector<int>a(l, -);
  20. for (i = ; i < l; i++)
  21. {
  22. scanf("%d", &a[i]);
  23. }
  24. vector<int>::iterator it = a.begin();
  25. for (; it != a.end(); it++)
  26. {
  27. if (p[*it]<)
  28. {
  29. it=a.erase(it);//erase()删除的用法.
  30. it--;
  31. }
  32. }
  33. vector<int>dp(a.size(), );
  34. int j;
  35. int ans = -;
  36. for (i = ; i < a.size(); i++)
  37. {
  38. for (j = ; j < i; j++)
  39. {
  40. if (p[a[i]]>=p[a[j]] && dp[j]+>dp[i])
  41. dp[i] = dp[j] + ;
  42. }
  43. ans = max(ans, dp[i]);
  44. }
  45. printf("%d\n", ans);
  46. }

[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. 关于SQL SERVER中的FLOAT转换为VARCHAR

    关于SQL SERVER中的FLOAT转换为VARCHAR 一个FLOAT型的字段,要转换为VARCHAR,可是小数点后面的都自动被删去了...后查得可以通过如下转换获得: SELECT CAST(C ...

  2. SQL Fundamentals: 子查询 || WHERE,HAVING,FROM,SELECT子句中使用子查询,WITH子句

    SQL Fundamentals || Oracle SQL语言 子查询(基础) 1.认识子查询 2.WHERE子句中使用子查询 3.在HAVING子句中使用子查询 4.在FROM子句中使用子查询 5 ...

  3. linux:基本指令touch, cp 和 mv

    touch 新建 #touch 的使用很简单, 我们先去往 Documents 的文件夹, 里面已经有了 folder1 和 file1, 如果我们想新建一个 file2 使用下面的语句就好. 一个空 ...

  4. /etc/apt/sources.list" E212: Can't open file for writing解决方案

    :w !sudo tee % > /dev/null 解决.

  5. haproxy实现会话保持

    HAProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.反向代理为什么需要设置cookie 任何一个七层的http负载均衡器,都 ...

  6. tomcat运行模式

    Tomcat Connector的三种不同的运行模式性能相差很大 这三种模式的不同之处如下: BIO: 一个线程处理一个请求.缺点:并发量高时,线程数较多,浪费资源. Tomcat7或以下,在Linu ...

  7. Xml文件删除节点总是留有空标签

    ---恢复内容开始--- 在删除Xml文件时,删除成功后还有标签,让我百思不得其解,因为xml文档中留着这空标签会对后续的操作带来很多麻烦,会取出空值,人后导致程序中止. 导致这种情况的原因是删除xm ...

  8. [development][C] C语言标准

    GUN C的标准文档: 也就是glibc https://www.gnu.org/software/libc/ http://man7.org/linux/man-pages/dir_section_ ...

  9. [troubleshoot][archliunx][chromium][flash] chrome提示flash不是最新

    最近chrome总是在提示flash不是最新要求更新. 原来以前用的flash包 chromium-pepper-flash 不见了,改名变成了pepper-flash. /home/tong [to ...

  10. 【Python全栈-JavaScript】JavaScript入门

    JavaScript基础知识点 一.JavaScript概述 参考:http://www.w3school.com.cn/b.asp JavaScript的历史 1.1992年Nombas开发出C-m ...