日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)

發布時間:2023/12/10 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【计蒜客 - 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.

樣例輸入復制

abcdefg 3 abc adg cba

樣例輸出復制

YES YES NO

題目大意:

? ?給你一個模板串,再給你n個串,問你這n個串能否由模板串的子序列構成。

解題報告:

出過好幾次的套路了。。。剛開始NO沒加\n,,,wa一發真可惜、、

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 ; }

?

總結

以上是生活随笔為你收集整理的【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。