rt,这是代码
#include<bits/stdc++.h>
using namespace std;
string nu;
int k;
map<char,vector<char>>op;
map<string,int>num;
int dfs(string s){
num[s]++;
if(num[s]!=1){
return 0;
}
int i=0;
for(auto ch:s){
if(!op[ch].empty()){
for(auto opr:op[ch]){
string s1=s;
s1[i]=opr;
dfs(s1);
}
}
i++;
}
return 0;
}
int main(){
cin>>nu>>k;
char o,n;
while(k--){
cin>>o>>n;
op[o].push_back(n);
}
dfs(nu);
cout<<num.size();
return 0;
}
开了O2: 1MLE 2TLE
没开O2: 3TLE