题意:

输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个正整数L(<=10000),代表条带的长度,接着输入L个正整数表示条带上的颜色的编号。输出以喜爱颜色顺序排列的最长子串长度(不必每种颜色都有,只保证相对位置相同,同种颜色可连续)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[],pos[];
int dp[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int color;
for(int i=;i<=m;++i){
cin>>color;
pos[color]=i;//记录颜色的相对位置
}
int cnt=;
int stripe;
int l;
cin>>l;
for(int i=;i<=l;++i){
cin>>stripe;
if(pos[stripe])
a[++cnt]=pos[stripe],dp[cnt]=;//记录条带上颜色在喜爱条带上的位置
}
int mx=;
for(int i=;i<=cnt;++i){
for(int j=;j<i;++j)//以相对位置j结尾的都可以在后面加上以相对位置i结尾的颜色
if(a[j]<=a[i])
dp[i]=max(dp[i],dp[j]+);//更新以相对位置i结尾的子串的长度
mx=max(mx,dp[i]);//选取最长长度作为答案
}
cout<<mx;
return ;
}

【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)的更多相关文章

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

  2. PAT甲级1045. Favorite Color Stripe

    PAT甲级1045. Favorite Color Stripe 题意: 伊娃正在试图让自己的颜色条纹从一个给定的.她希望通过剪掉那些不必要的部分,将其余的部分缝合在一起,形成她最喜欢的颜色条纹,以保 ...

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

  4. PAT 甲级 1045 Favorite Color Stripe

    https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...

  5. PAT 甲级 1045 Favorite Color Stripe(DP)

    题目链接 Favorite Color Stripe 题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列 (这个子序列的相邻元素可以重复) ...

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

  7. PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***

    1068 Find More Coins (30 分)   Eva loves to collect coins from all over the universe, including some ...

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

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

随机推荐

  1. 使用git pull同步github代码到服务器

    我直接用git pull的时候遇到这个错误: error: Your local changes to the following files would be overwritten by merg ...

  2. 题解 P5530 [BalticOI 2002]双调路径

    P5530 [BalticOI 2002]双调路径 输入样例: 4 5 1 4 2 1 2 1 3 4 3 1 2 3 1 2 3 1 1 4 2 4 2 4 样例如下图 样例说明: 从1到4有4条路 ...

  3. 【网易官方】极客战记(codecombat)攻略-地牢-攻破突袭

    关卡连接: https://codecombat.163.com/play/level/hack-and-dash 通过加速药来逃离地牢精灵 简介: 空气中弥漫着危险的气息.你应该从地牢里逃出来. 但 ...

  4. MSYS2与mingw32和mingw64的安装

    由于编译OpenBLAS接触到MSYS2. 下载MSYS:https://mirror.tuna.tsinghua.edu.cn/help/msys2/ 安装,并按照下面的配置,然后可以安装mingw ...

  5. Go_栈

    1. 栈的介绍 2. 栈的应用 3. 栈入门 package main import ( "fmt" "errors" ) //使用数组来模拟一个栈的使用 ty ...

  6. 时间类型:datetime,timestamp,date,time,year

    时间类型 1.年月日时分秒:datetime #取值范围# '1000-01-01 00:00:00'到'9999-12-31 23:59:59' 占存储8B:表示的范围比timestamp大:支持0 ...

  7. 【REST详述及RESTful规范】

    目录 Web服务交互 理解REST 什么是资源? 什么是URI.URL? 统一资源接口 资源的表述 状态转移 小结 "RESTful是一种软件的架构风格.设计风格,为客户端和服务端的交互提供 ...

  8. SpringMVC:ssm整合练习一

    西部开源-秦疆老师:MyBatis,Spring,SpringMVC 整合练习一 , 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! ss ...

  9. JavaScript 推箱子游戏

    推箱子游戏的 逻辑非常简单,但是如果不动手的话,还是不太清楚.我在这里讲一下自己的思路. 制作推箱子,首先要有自己的设计素材.如下我也是网上找的素材 第二步,理清游戏的规则. 游戏规则: 1.小人将箱 ...

  10. Spring Boot Json 之 Jackjson Fastjson

    Json 是目前互联网应用使用最为广泛的信息交换格式之一.Spring Boot 内置了 Jackson .Json 在应用中主要体现在以下功能: 序列化 反序列化 字段格式化 验证自动化 目前长用的 ...