Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.

It is said that a normal human eye can distinguish about less than 200 different colors, so Eva's favorite colors are limited. However the original stripe could be very long, and Eva would like to have the remaining favorite stripe with the maximum length. So she needs your help to find her the best result.

Note that the solution might not be unique, but you only have to tell her the maximum length. For example, given a stripe of colors {2 2 4 1 5 5 6 3 1 1 5 6}. If Eva's favorite colors are given in her favorite order as {2 3 1 5 6}, then she has 4 possible best solutions {2 2 1 1 1 5 6}, {2 2 1 5 5 5 6}, {2 2 1 5 5 6 6}, and {2 2 3 1 1 5 6}.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (≤) which is the total number of colors involved (and hence the colors are numbered from 1 to N). Then the next line starts with a positive integer M (≤) followed by M Eva's favorite color numbers given in her favorite order. Finally the third line starts with a positive integer L (≤) which is the length of the given stripe, followed by L colors on the stripe. All the numbers in a line a separated by a space.

Output Specification:

For each test case, simply print in a line the maximum length of Eva's favorite stripe.

Sample Input:

6
5 2 3 1 5 6
12 2 2 4 1 5 5 6 3 1 1 5 6

Sample Output:

7

题目分析:按照要求要截取袋子 但每次截取都必须按照给定的顺序来截取 对于每一种颜色 利用先后顺序为它编号 读取过程中去除掉未被编号的袋子 对余下的袋子进行动态规划 
对于每个dp[i]来说 从j到i重新比较 dp[i]与dp[j]+1 最后找到最大值
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int color[];
int dp[];
int Array[];
int main()
{
int N, M;
cin >> N >> M;
int col;
for (int i = ; i <= M; i++)
{
cin >> col;
color[col] = i;
}
int K, num = ;;
cin >> K;
for (int i = ; i < K; i++)
{
cin >> col;
if (color[col])
Array[num++] = color[col];
}
int maxn = ;
for (int i = ; i<num; i++)
{
dp[i] = ;
for (int j = ; j < i; j++)
if (Array[j] <= Array[i])
dp[i] = max(dp[i], dp[j] + );
maxn = max(maxn, dp[i]);
}
cout << maxn;
}

1045 Favorite Color Stripe (30分)(简单dp)的更多相关文章

  1. 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)

    题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...

  2. 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 ...

  3. 1045 Favorite Color Stripe (30)(30 分)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  4. 1045 Favorite Color Stripe (30)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  5. 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 ...

  6. 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 ...

  7. PAT (Advanced Level) 1045. Favorite Color Stripe (30)

    最长公共子序列变形. #include<iostream> #include<cstring> #include<cmath> #include<algori ...

  8. 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. ...

  9. 1045 Favorite Color Stripe 动态规划

    1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...

随机推荐

  1. 结题报告--P5551洛谷--Chino的树学

    题目:点此 题目描述 Chino树是一棵具有某种性质的满二叉树,具体来说,对于这棵树的每一个非叶子节点,它的左子节点(A)(A)(A)的右子节点(C)(C)(C)与它的右子节点(B)(B)(B)的左子 ...

  2. Linux apache让网页编码错误

    今天帮一个小伙伴搞作业,遇到安装discuz乱码问题,就顺便在这里写一下,以供其他同学纠正. 开apache配置文件/etc/httpd/conf/httpd.conf 查找AddDefaultCha ...

  3. 【tomcat系列】配置tomcat远程访问

    当程序部署在tomcat上后,需要监测tomcat的性能和监测tomcat的各项指标,如内存使用情况,cpu使用情况,jvm实际情况等,对于这些指标的监控,tomcat提供了访问入口,然而tomcat ...

  4. JS的3种核心设计模式

    一.单例模式 1.保证一个类仅有一个实例,并提供一个访问它的全局访问点 2.设计思路:如果存在,不创建,直接返回,不存在才创建. 在类的constructor方法里添加一个判断条件属性,并且让创建的实 ...

  5. Druid连接池和springJDbc框架-Java(新手)

    Druid连接池: Druid 由阿里提供 安装步骤: 导包 durid1.0.9 jar包 定义配置文件 properties文件 名字任意位置也任意 加载文件 获得数据库连接池对象 通过Durid ...

  6. java-随机点名2(新手)

    //创建的一个包名. package qige; //导入一个包.import java.util.*; //定义一个类.public class SJdm { //公共静态的主方法. public ...

  7. Swift中的感叹号( ! )与问号( ? )之谜

    基本了解 在Swift代码会经常看到定义属性或方法参数时类型后面会紧跟一个感叹号( ! )或问号( ? ), 刚开始接触Swift的童鞋就可能不太明白之代表什么意思,一头雾水,开始凌乱了. 本文将带你 ...

  8. iOS 指纹认证登陆开发(TouchID)

    设计思路 TouchID 关联账号 用户登陆成功 -> 开启TouchID登陆 -> TouchID验证 -> 记录用户信息(验证通过) -> 关联完成 TouchID 登陆 ...

  9. gdb中的gef插件

    地址 https://github.com/hugsy/gef # via the install script #下载 `gef.sh` 并执行 wget -q -O- https://github ...

  10. drf 权限认证

    目录 复习 前期准备 三大认证简介 AbstracUser源码分析 自定义User下的权限六表 models.py 到settings.py中注册 注意点: 执行数据迁移的俩条命令 创建超级用户 t_ ...