题目大意:
给出n个数组成的一个串,这n个数的范围是1~k,求出最短非子序列的串(这个串只能由1~k中的数字组成)
分析:
额(⊙o⊙)…不会
题解是这么写的:
从前往后扫描,把原串划分成若干个序列,使得这些序列满足包含所有的1~k的数字,并且至少有一个数字只出现过一次,答案就是序列个数+1
代码如下:
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=100000+5,maxk=10000+5;
int n,k,a[maxn],ans;
bool vis[maxk];
inline int read(void){
char ch=getchar();
int f=1,x=0;
while(!(ch>='0'&&ch<='9')){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
x=x*10+ch-'0',ch=getchar();
return f*x;
}
inline bool check(){
for(int i=1;i<=k;i++)
if(!vis[i])
return false;
memset(vis,0,sizeof(vis));
return true;
}
signed main(void){
n=read(),k=read(),ans=0;
for(int i=1;i<=n;i++)
a[i]=read();
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
vis[a[i]]=1;
if(check())
ans++;
}
printf("%d\n",ans+1);
return 0;
}
by >o< neighthorn