Hello XTCPC
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1207 Accepted Submission(s): 337
Problem Description
You have a string of lowercase letters.You need to find as many sequence “xtCpc” as possible.But letters in the same position can only be used once。
Input
The input file contains two lines.
The first line is an integer n show the length of string.(1≤n≤2×105)
The second line is a string of length n consisting of lowercase letters and uppercase letters.
Output
The input file contains an integer show the maximum number of different subsequences found.
Sample Input
10
xtCxtCpcpc
Sample Output
2
有顺序要求
Source
2019CCPC湖南全国邀请赛(广东省赛、江苏省赛)重现赛
Recommend
liuyiding
#include<stdio.h>
#include<string.h>
char s[200010];
int b[200010];
int main()
{
int i,n,a1,a2,a3,a4,a5,len,count;
while(~scanf("%d",&n))
{
a1=a2=a3=a4=a5=0;
scanf("%s",s);
len=strlen(s);
count=0;
for(i=0;i<len;i++)
{
if(s[i]=='x')
a1++;
if(s[i]=='t'&&a2<a1)// i之前的字母出现的个数要比i个数多
a2++;
if(s[i]=='C'&&a3<a2)
a3++;
if(s[i]=='p'&&a4<a3)
a4++;
if(s[i]=='c'&&a5<a4)
a5++;
if(a1&&a2&&a3&&a4&&a5)
{
count++;
a1--;
a2--;
a3--;
a4--;
a5--;
}
}
printf("%d\n",count);
}
return 0;
}