【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)
題干:
Give a string?SS?and?NN?string?T_iTi??, determine whether?T_iTi??is a subsequence of?SS.
If ti is subsequence of?SS, print?YES,else print?NO.
If there is an array?\lbrace K_1, K_2, K_3,\cdots, K_m \rbrace{K1?,K2?,K3?,?,Km?}?so that?1 \le K_1 < K_2 < K_3 < \cdots < K_m \le N1≤K1?<K2?<K3?<?<Km?≤N?and?S_{k_i} = T_iSki??=Ti?,?(1 \le i \le m)(1≤i≤m), then?T_iTi??is a subsequence of?SS.
Input
The first line is one string?SS,length(SS)?\le 100000≤100000
The second line is one positive integer?N,N \le 100000N,N≤100000
Then next?nn?lines,every line is a string?T_iTi?, length(T_iTi?)?\le 1000≤1000
Output
Print?NN?lines. If the?ii-th?T_iTi??is subsequence of?SS, print?YES, else print?NO.
樣例輸入復(fù)制
abcdefg 3 abc adg cba樣例輸出復(fù)制
YES YES NO題目大意:
? ?給你一個(gè)模板串,再給你n個(gè)串,問你這n個(gè)串能否由模板串的子序列構(gòu)成。
解題報(bào)告:
出過好幾次的套路了。。。剛開始NO沒加\n,,,wa一發(fā)真可惜、、
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e5 + 5; string ss; char s[MAX]; int trie[MAX][66]; int main() {int n;cin>>ss;int len = ss.size();ss = ' ' + ss;for(int j = 0; j<26; j++) trie[len+1][j] = -1;for(int i = len; i>=1; i--) {for(int j = 0; j<26; j++) {if(j == ss[i] - 'a') trie[i][j] = i;else trie[i][j] = trie[i+1][j];}}cin>>n;for(int i = 1; i<=n; i++) {int cur = 0;scanf("%s",s);int up = strlen(s);for(int j = 0; j<up; j++) {cur = trie[cur+1][s[j] - 'a'];if(cur == -1) {break;}}if(cur != -1) printf("YES\n");else printf("NO\n");}return 0 ; }?
總結(jié)
以上是生活随笔為你收集整理的【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 屏蔽30余款安全软件:Adobe Acr
- 下一篇: winmgm32.exe - winmg