PAT 甲级 1045 Favorite Color Stripe(DP)
题目链接 Favorite Color Stripe
题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列
(这个子序列的相邻元素可以重复)
只要求出这个子序列长度的最大值即可
很基础的DP题,设$f[i]$为当前以$a[i]$结尾的子序列的长度的最大值,扫描$B$序列的每个元素时实时更新即可。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int L = 10010;
const int N = 210; int a[L], c[N], f[N];
vector <int> v[N];
int n, m, l;
int ans; int main(){ scanf("%d%d", &n, &m);
rep(i, 1, m){
scanf("%d", c + i);
v[c[i]].push_back(i);
} scanf("%d", &l);
rep(i, 1, l) scanf("%d", a + i); rep(i, 1, l){
for (auto u : v[a[i]]){
if (f[u]) ++f[u];
rep(j, 0, u - 1) f[u] = max(f[u], f[j] + 1); }
} rep(i, 1, m) ans = max(ans, f[i]);
return 0 * printf("%d\n", ans);
}
PAT 甲级 1045 Favorite Color Stripe(DP)的更多相关文章
- 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 ...
- PAT 甲级 1045 Favorite Color Stripe
https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...
- 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甲级——A1045 Favorite Color Stripe
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 动态规划
1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...
- 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...
- 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 ...
随机推荐
- leetcode-24-exercise
506. Relative Ranks 解题思路: 使用priority_queue.它在插入时会将数据按照由大到小的顺序插入,自然排序了.所以插入时考虑插入pair<nums[i],i> ...
- LeetCode (160) Intersection of Two Linked Lists
题目 Write a program to find the node at which the intersection of two singly linked lists begins. For ...
- GPIO程序在PC上的模拟学习
#include <stdio.h> #include <malloc.h> #include <memory.h> typedef struct gpio { i ...
- 【HIHOCODER 1055】 刷油漆(树上背包)
描述 小Ho有着一棵灰常好玩的树玩具!这棵树玩具是由N个小球和N-1根木棍拼凑而成,这N个小球都被小Ho标上了不同的数字,并且这些数字都是处于1..N的范围之内,每根木棍都连接着两个不同的小球,并且保 ...
- BZOJ 5064: B-number
数位DP #include<cstdio> #include<cstring> using namespace std; int A[16]; long long F[16][ ...
- 01_Java 软、弱引用语法介绍
文章导读: 从JDK1.2版本开始,把对象的引用分为四种级别,从而使程序能更加灵活的控制对象的生命周期.这四种级别由高到低依次为:强引用.软引用.弱引用和虚引用, 本章内容介绍了Reference的概 ...
- TensorFlow——热身运动:简单的线性回归
过程: 先用numpy建立100个数据点,再用梯度下滑工具来拟合,得到完美的回归线. # _*_coding:utf-8_*_ import tensorflow as tf import numpy ...
- 对于运用git将本地文件上传到coding总结
首先需要在你的本地磁盘下建立一个目录,并且进入该目录. 前几次课程上有讲到&的用法,&&表示并且. 命令 ”makir 文件名 && cd 文件名”,cd指进入 ...
- Unity3D - UGUI的手动搭建
了解UGUI组件的搭建方式,有助于搭建我们自己的UI界面. Text 文本 text 是UGUI中的基本控件,在Hierarchyi面板创建一个空物体 - 给这个空物体添加一个Text组件即可实现与t ...
- 刷题总结——生日礼物(bzoj1293单调队列)
题目: Description 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有N个,分为K种.简单的说,可以将彩带考虑为x轴,每一个彩珠有一个对应的坐标(即位置).某些坐标上可以没有彩珠, ...