"Link" I am the link, point me:)
Test instructions
Exercises
Dictionary Tree
We can double cycle (i,j)
To enumerate all the substrings
That is i=1,j=1,2,3 ...
I=2,j = 2,3,4,..
So we are at the time of I change (that is, the J layer cycle is over, I want to execute i+1
Make the root of the cur= dictionary tree
Then go down the dictionary tree.
When we encounter a position that has not been traversed, we find a substring that we have not encountered before.
Then we'll ++tot to create a new node according to the rules of the dictionary tree.
Otherwise, if there is this node, then go down and walk on it, indicating this substring s[i. J] There have been
Then if the special letter >=k, then the direct break can be.
The number of nodes in the last dictionary tree is the number of substrings that meet the requirements.
Code
#include <bits/stdc++.h>#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)using namespace std;const int N = 1500*1500;string s;string dic;int ch[N+10][26];int k,tot,root = 1;int main(){ #ifdef LOCAL_DEFINE freopen("rush.txt","r",stdin); #endif // LOCAL_DEFINE ios::sync_with_stdio(0),cin.tie(0); cin >> s; cin >> dic; cin >> k; tot = 1; rep1(i,0,(int)s.size()-1){ int cur = root; int cnt = 0; rep1(j,i,(int)s.size()-1){ if (dic[s[j]-'a']=='0') cnt++; if (cnt>k) break; if (ch[cur][s[j]-'a']==0)ch[cur][s[j]-'a']=++tot; cur = ch[cur][s[j]-'a']; } } cout<<tot-1<<endl; return 0;}
"Codeforces 271D" good substrings