Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 2000;
- char str[N + 2], tr[N + 2];
- bool dp[N + 1][N + 1];
- int main(){
- int Q;
- scanf(" %s%d", str + 1, &Q);
- int len = strlen(str + 1);
- while(Q--){
- scanf(" %s", tr + 1);
- int tlen = strlen(tr + 1);
- dp[0][0] = true;
- for(int i = 0; i <= len; ++i){
- for(int j = 1; j <= tlen; ++j){
- if(tr[j] == '$'){
- bool ans = false;
- if(i != 0){
- ans |= dp[i - 1][j];
- }
- ans |= dp[i][j - 1];
- dp[i][j] = ans;
- } else if(tr[j] == '-'){
- dp[i][j] = i != 0 && dp[i - 1][j - 1];
- } else {
- dp[i][j] = i != 0 && tr[j] == str[i] && dp[i - 1][j - 1];
- }
- }
- }
- if(dp[len][tlen]){
- cout << "success\n";
- } else {
- cout << "fail\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement