数据
输入:
11111111111111111111 2
1 2
2 1
应该输出
1048576
不应该啊
#include<map>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string n, q[1000005];int len, k, x[20], y[20];
map<string, int> m1;
void Bfs() {
int ans = 1, l = 1, r = 1;
q[1] = n; m1[n] = 1;
while(l <= r) {
for(int i = 1; i <= k; ++i) {
for(int j = 0; j < len; ++j) {
//cout << q[l][j] << " " << x[i] << " "<< y[i] << endl;
if (q[l][j] - '0' == x[i]) {
string n1 = q[l];
n1[j] = y[i] + '0';
if (!m1[n1]) {
q[++r] = n1;
m1[n1] = 1;
++ans;
}
}
}
}
++l;
}
printf("%d\n", ans);
}
int main() {
cin >> n >> k;
len = n.size();
for(int i = 1; i <= k; ++i)
scanf("%d%d", x + i, y + i);
Bfs();
return 0;
}