麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

1045. Favorite Color Stripe (30)

2019-11-11 04:59:45
字體:
來源:轉載
供稿:網友

1045. Favorite Color Stripe (30)

時間限制 200 ms內存限制 65536 kB代碼長度限制 16000 B判題程序 Standard 作者 CHEN, Yue

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 (<=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 (<=10000) which is the length of the given stripe, followed by L colors on the stripe. All the numbers in a line are 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:

65 2 3 1 5 612 2 2 4 1 5 5 6 3 1 1 5 6

Sample Output:

7

#include<iostream>#include<algorithm>using namespace std; int color[201]={0};//記錄某一顏色是否是最喜歡的顏色 int main(){	int N,M,i,j,temp,count=0;	cin>>N;	cin>>N;	int *a=new int[N];	for(i=0;i<N;i++){		scanf("%d",&a[i]);		color[a[i]]=++count;	}	count=0;	cin>>M;	int *b=new int[M];	for(i=0;i<M;i++){		scanf("%d",&temp);		if(color[temp]>0)//只保留在最喜歡的顏色里出現過的顏色 		b[count++]=temp;	}	M=count;	int *c=new int[M];	for(i=0;i<M;i++)	c[i]=1;	int max;	for(i=M-1;i>=0;i--){//計算每個字符之后的字符串最大長度 		max=0;	for(j=M-1;j>i;j--)		if(color[b[j]]>=color[b[i]])		if(max<c[j])		max=c[j];	c[i]=max+1;	}	for(i=0;i<M;i++)//找到最大長度 		if(c[i]>max)		max=c[i];	cout<<max;} 感想:想了很久只想到這種方法,從后往前,每個符合要求的字符后的字符串長度是后面的字符符合要求的字符串的長度加一,這樣一直循環就可以得到最大值
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久久国产成人免费精品免费 | 99精品视频在线导航 | 成人在线免费视频观看 | 国产日产精品一区四区介绍 | 一级黄色免费观看 | 黄色成人av在线 | 国产精品久久久久久久av三级 | 日韩视频精品一区 | 最新av网址在线观看 | 欧美一级黄色片免费观看 | 欧美国产成人在线 | 国产高潮好爽受不了了夜色 | 国产精品免费成人 | 亚洲小视频在线播放 | 色婷婷tv| 久久国产夫妻视频 | 失禁高潮抽搐喷水h | 久久久三级免费电影 | 天天透天天狠天天爱综合97 | 欧美a在线观看 | 在线成人看片 | 中午字幕无线码一区2020 | 欧美精品18| 美国黄色毛片女人性生活片 | 91精品片 | 色a综合 | 最新中文字幕第一页视频 | 国产精品一区二区三区在线 | 中国免费一级毛片 | a级毛片免费观看在线播放 日本aaa一级片 | 一级黄色a视频 | 羞羞网站在线观看入口免费 | 欧美成人激情在线 | 日本xxxx视频| 亚洲aⅴ在线观看 | 久久久精品综合 | av电影在线免费 | 国产精品一区二区羞羞答答 | 性欧美xxxx免费岛国不卡电影 | 午夜视频成人 | 久久久久久亚洲国产精品 |