1045 Favorite Color Stripe (30分)(简单dp)
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)的更多相关文章
- 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1045. Favorite Color Stripe (30)
最长公共子序列变形. #include<iostream> #include<cstring> #include<cmath> #include<algori ...
- 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. ...
- 1045 Favorite Color Stripe 动态规划
1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...
随机推荐
- 前端传json数组 ,后端的接收
前端传输: var updateGoodsId=$(this).val();//get id var updateGoodsPrice=$("#IngoodsPrice"+upda ...
- 谈谈集合.Map
本文来谈谈我们平时使用最多的HashMap. 1. 简介 HashMap是我们在开发过程中用的最多的一个集合结构,没有之一.HashMap实现了Map接口,内部存放Key-Value键值对,支持泛型. ...
- 06 yarn是什么
yarn集群中有两个角色: 主节点:Resource Manager 1台 从节点:Node Manager N台 Resource Manager一般安装在一台专门的机器上 Node Mana ...
- mysql 多个字段重复记录查询
select * from productstockquantity t where () ORDER BY t.CombinationI
- node 微信支付
基于node 实现微信支付功能 需要了解的网站:微信支付 流程图: 1. 1.我的路由: const Koa = require('koa') const app = new Koa() const ...
- 一、create-react-app的安装及使用
一.安装create-react-app 1.在全局环境中安装create-react-app npm install -g create-react-app 2.在您所需要的目录(盘)下生成一个项目 ...
- java第一次上机练习作业
1.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序.(知识点:变量和 运算符综合应用) int a = 5, b = 10; int temp; temp = a; a = b; b = ...
- java 知识点总结(转)
转载自 https://www.cnblogs.com/wl310538259/p/5218251.html (一)Java 1.接口和抽象类的区别 ①抽象类里可以有构造方法,而接口内不能有构造方法. ...
- 从零开始学习R语言(五)——数据结构之“列表(List)”
本文首发于知乎专栏:https://zhuanlan.zhihu.com/p/60141740 也同步更新于我的个人博客:https://www.cnblogs.com/nickwu/p/125678 ...
- Multi-batch TMT reveals false positives, batch effects and missing values(解读人:胡丹丹)
文献名:Multi-batch TMT reveals false positives, batch effects and missing values (多批次TMT定量方法中对假阳性率,批次效应 ...