40求助
查看原帖
40求助
1411407
yyc0717yyc楼主2025/8/4 12:57
#include <bits/stdc++.h>
using namespace std;

vector<char> a[128];
unordered_map<string, bool> mp;
string s;
int n, ans;

void dfs(string s) {
	if (mp[s]) return;
	mp[s] = true; ans++;
	int len = s.size();
	for (int i = 0; i < len; i++) {
		string t = s;
		for (char u : a[t[i]]) {
			t[i] = u;
			dfs(t);
		}
	}
	return;
}

int main() {
	cin >> s >> n;
	for (int i = 1; i <= n; i++) {
		char x, y;
		cin >> x >> y;
		a[x].push_back(y);
	}
	dfs(s);
	cout << ans;
	return 0;
}
2025/8/4 12:57
加载中...