1045 Favorite Color Stripe
作者:互联网
1045 Favorite Color Stripe
先把需要的字符按照输入的顺序赋予权值,然后去掉不需要的字符,再求最长不递减序列的长度就可以了。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<sstream>
typedef long long ll;
using namespace std;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int MAXN=1E4+7;
int n, m, l;
int w[207], squ[MAXN];
int main()
{
scanf("%d%d", &n, &m);
int t;
for(int i=0; i<m; i++){
scanf("%d", &t);
w[t] = i+1;
}
scanf("%d", &l);
int len = 0;
for(int i=0; i<l; i++){
scanf("%d", &t);
if(w[t]>0)
squ[len++]=w[t];
}
l = len;
len = 1;
for(int i=1; i<l; i++){
if(squ[i] >= squ[len-1]) //注意是不递减的序列
squ[len++] = squ[i];
else{
//不递减意味着应该找到一个大于它的位置
int j=upper_bound(squ, squ+len, squ[i])-squ;
squ[j] = squ[i];
}
}
printf("%d\n", len);
return 0;
}
标签:递减,const,Color,Favorite,squ,len,int,Stripe,include 来源: https://www.cnblogs.com/alking1001/p/14526062.html