传送门
1 #include<iostream>
2 #include<cstring>
3 #include<cstdlib>
4 #include<cstdio>
5 #include<algorithm>
6 #include<cmath>
7 #include<queue>
8 #include<map>
9 #include<set>
10 #include<stack>
11 #include<string>
12
13 #define N 2250005
14 #define M 1505
15 #define mod 10000007
16 //#define p 10000007
17 #define mod2 1000000000
18 #define ll long long
19 #define LL long long
20 #define eps 1e-6
21 #define inf 100000000
22 #define maxi(a,b) (a)>(b)? (a) : (b)
23 #define mini(a,b) (a)<(b)? (a) : (b)
24
25 using namespace std;
26
27 int n;
28 int T;
29 int flag;
30 int ccount;
31 char ss[M];
32 char f[30];
33
34 typedef struct
35 {
36 int v;
37 vector<int>nt;
38 }PP;
39
40 PP p[N];
41 int le;
42
43 int k;
44 int tot;
45
46 void insert(char s[])
47 {
48 int l=strlen(s);
49 int i;
50 int ff;
51 int st=0;
52 int y;
53 vector<int>::iterator it;
54 for(i=0;i<l;i++){
55 ff=0;
56 for(it=p[st].nt.begin();it!=p[st].nt.end();it++){
57 y=*it;
58 if(p[y].v==s[i]-'a'){
59 ff=1;
60 st=y;
61 break;
62 }
63 }
64 if(ff==0){
65 p[st].nt.push_back(tot);
66 p[tot].v=s[i]-'a';
67 p[tot].nt.clear();
68 st=tot;
69 tot++;
70 }
71 }
72 }
73
74 void ini()
75 {
76 ccount=0;
77 int i;
78 scanf("%s",f);
79 scanf("%d",&k);
80 flag=1;
81 p[0].nt.clear();
82 p[0].v=-1;
83 tot=1;
84 scanf("%d",&n);
85 le=strlen(ss);
86 for(i=0;i<le;i++){
87 insert(ss+i);
88 }
89 }
90
91 void check(int st,int now)
92 {
93 //printf(" st=%d v=%d now=%d
",st,p[st].v,now);
94 int y;
95 if(now>k) return;
96 ccount++;
97 vector<int>::iterator it;
98 for(it=p[st].nt.begin();it!=p[st].nt.end();it++)
99 {
100 y=*it;
101 //printf(" st=%d y=%d f=%c
",st,y,f[ p[y].v ]);
102 if(f[ p[y].v ]=='1'){
103 check(y,now);
104 }
105 else{
106 check(y,now+1);
107 }
108 }
109 }
110
111 void solve()
112 {
113 //printf("solve
");
114 ccount=-1;
115 check(0,0);
116 }
117
118 void out()
119 {
120 printf("%d
",ccount);
121 }
122
123 int main()
124 {
125 //freopen("data.in","r",stdin);
126 //freopen("data.out","w",stdout);
127 //scanf("%d",&T);
128 //for(int ccnt=1;ccnt<=T;ccnt++)
129 //while(T--)
130 //scanf("%d%d",&n,&m);
131 while(scanf("%s",ss)!=EOF)
132 {
133 ini();
134 solve();
135 out();
136 }
137 return 0;
138 }