1045 Favorite Color Stripe
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}.
Each input file contains one test case. For each case, the first line contains a positive integer N (≤200) 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 (≤200) followed by M Eva's favorite color numbers given in her favorite order. Finally the third line starts with a positive integer L (≤104) 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.
For each test case, simply print in a line the maximum length of Eva's favorite stripe.
- 6
- 5 2 3 1 5 6
- 12 2 2 4 1 5 5 6 3 1 1 5 6
7
总结:这是一道DP题目,而且还是需要转化一下,现在的能力属实不会做,不过这道题目和这道题目是差不多的
- #include
- using namespace std;
- int a[210],b[10010],d[10010];
-
- int main(){
- int n,m;
- cin >> n >> m;
-
- int x,num=0,maxan=0;
- for(int i=1;i<=m;i++){
- scanf("%d",&x);
- a[x]=i;
- }
-
- cin >> m;
- for(int i=0;i
- scanf("%d",&x);
- if(a[x]>=1){
- b[num++]=a[x];
- }
- }
-
- for(int i=0;i
- d[i]=1;
- for(int j=0;j
- if(b[i]>=b[j]) d[i]=max(d[i],d[j]+1);
- }
- maxan=max(maxan,d[i]);
- }
-
- printf("%d",maxan);
-
- return 0;
- }
好好学习,天天向上!
我要考研!
2022.11.10
- #include
- using namespace std;
- int a[210],b[10010],d[10010];
-
- int main(){
- int n,m;
- scanf("%d%d",&n,&m);
-
- int num=0,x,maxn=0;
- for(int i=1;i<=m;i++){
- scanf("%d",&x);
- a[x]=i;//存下该种颜色的顺序
- }
-
- scanf("%d",&m);
- for(int i=0;i
- scanf("%d",&x);
- if(a[x]>=1)//如果这种颜色是喜欢的颜色
- b[num++]=a[x];//按顺序存储每一种颜色的喜欢顺序
- }
-
- for(int i=0;i
- d[i]=1;
- for(int j=0;j
- if(b[i]>=b[j])//以第i个颜色结尾,最长的颜色序列的长度
- //如果该种颜色的顺序在第j种颜色之后,那么可以将第j个颜色加入i的前面
- d[i]=max(d[i],d[j]+1);
- maxn=max(maxn,d[i]);
- }
-
- printf("%d\n",maxn);
- return 0;
- }
-
-
相关阅读:
字体反爬积累知识
户外景区亲子儿童剧本杀小程序系统开发搭建
2.1.9.4 MySQL udf提权
Spring Boot整合OAuth2实现GitHub第三方登录
设置session失效时间
1.报表平台规划
asp.net 应用程序中同步方法调用异步方法无响应解决方法
深入浅出理解分布式一致性Paxos算法
wechaty-puppet-whatsapp的uos协议使用中常见问题
高级前端进阶(五)
-
原文地址:https://blog.csdn.net/weixin_50679551/article/details/127038540
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU