http://www.lydsy.com/JudgeOnline/problem.php?id=1966
难道出题人没学过生物?RNA明明是AUCG(啊我真对得起我们生物老师)。。
带'*'和'?'的匹配,DP,单次O(n^2)
还好不是SDOI用AC自动机
//#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
/************************************************
Code By willinglive Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/
int m;
char s[1010];
char ss[510];
bool f[1010][510];
int c[1010];
/
inline bool cal(char x,char y)
{
if(x==y) return 1;
if(x=='?') return 1;
return 0;
}
bool check(char *ss)
{
MS(f,0); MS(c,0x3f);
f[0][0]=1;
int ls=strlen(s+1),lss=strlen(ss+1);
rep(i,1,ls)
{
if(s[i]!='*')
{
rep(j,1,lss)
{
if(f[i-1][j-1] && cal(s[i],ss[j])) f[i][j]=1;
else if(i!=1 && s[i-1]=='*' && c[i-1]<j && cal(s[i],ss[j])) f[i][j]=1;
}
}
else
{
if(i==1) f[1][0]=1;
rep(j,1,lss)
{
f[i][j]=f[i-1][j]||f[i][j-1];//'*'不匹配
if(f[i][j]) c[i]=min(c[i],j);
}
}
}
return f[ls][lss];
}
/
void input()
{
scanf("%s",s+1);
m=strlen(s+1);
rep(i,1,m) if(s[i]=='*') m--;
}
void solve()
{
int ans=0;
rep(i,1,read())
{
scanf("%s",ss+1);
if(!check(ss)) ans++;
}
cout<<ans<<endl;
}
/
int main()
{
#ifndef _TEST
freopen("std.in","r",stdin); freopen("std.out","w",stdout);
#endif
input(),solve();
return 0;
}