题目链接:http://codeforces.com/contest/779/problem/D
题意是给出两个字符串str和s,然后输入len个数(len为str的长度),依次删除str中第pre[i]个字符,问最多删除可以删除多少个字符,使得s还是str的子序列。
思路就是二分答案,去Check验证,实现过程也不难
AC代码:
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
string s,str;
int pre[maxn];
int num,s_len,len;
bool Check(int xx){
string ch = str;
for(int i=1;i<=xx;i++){
ch[pre[i] - 1] = '.';
}
int j = 0;
for(int i=0;i<len;i++){
if(ch[i] == s[j]){
j++;
}
if(j == s_len)break;
}
if(j == s_len)return true;
else return false;
}
int main()
{
cin>>str;
cin>>s;
len = str.length();
s_len = s.length();
for(int i=1;i<=len;i++){
scanf("%d",&pre[i]);
}
int l = 0, r = len, mid, ans;
while(l <= r){
mid = (l + r) >> 1;
if(Check(mid)){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
printf("%d\n", ans);
return 0;
}