题意:
在a字符串中删除某个w子串(可以分散的),问能到多少种b字符串。
样例:
Input
weewrshkim sim
Output
1
Input
qqqaaabbbcccfffrrr qabcfr
Output
729
思路:
题目意思实则就是求a串中的w串有多少种组成种类。
dp[i][j] 表示 a串前i个字符 构成w字符串前j个字母的方案数。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <string.h>
#include <string>
#include <queue>
#include <set>
#include <bits/stdc++.h>
using namespace std;
string str;
char ch[14];
vector<int> id[222];
long long dp[11];
const int MOD=1e9+7;
int main(){
cin>>str;
scanf("%s",ch+1);
int len=strlen(ch+1);
// memset(id,-1,sizeof id);
for(int i=1;i<=len;i++){
id[ch[i]-'A'].push_back(i);
}
dp[0]=1;
int len2=str.length();
str = '0'+str;
for(int i=1;i<=len2;i++){
int cnt;
for(int j=id[str[i]-'A'].size()-1;j>=0;j--){
cnt=id[str[i]-'A'][j];
dp[cnt]+=dp[cnt-1];
dp[cnt]%=MOD;
}
}
cout<<dp[len]%MOD<<endl;
}