-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00947.cpp
More file actions
73 lines (61 loc) · 1.6 KB
/
Copy path00947.cpp
File metadata and controls
73 lines (61 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll sum = 0;
set<char> hm;
string a; ll cc,cw;
set<string> hi;
void brute(ll depth, ll c, string temp = ""){
if(c>cc) return;
else if(depth==a.length()){
if(c==cc) {
ll w = 0;
bool result = true;
map<char, ll> freqq;
map<char, ll> freq;
for(ll i = 0; i < temp.length(); i++){
if(temp[i] != a[i]) ++freq[a[i]];
if(temp[i] != a[i] && hm.find(temp[i]) != hm.end()){
++w;
++freqq[temp[i]];
}
}
for(ll i = 0; i < temp.length(); i++){
if(temp[i] != a[i] && freqq[temp[i]] != freq[temp[i]]){
result = false;
break;
}
}
if(w == cw && result) hi.insert(temp);
}
}
else{
for(char g = '1'; g <= '9'; g++){
if(a[depth] == g){
hm.erase(g);
brute(depth+1, c+1, temp+g);
hm.insert(g);
}
else brute(depth+1, c, temp+g);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t; cin >> t;
while(t--){
hm.clear(), hi.clear();
cin >> a >> cc >> cw;
for(ll i = 0; i < a.length(); i++){
hm.insert(a[i]);
}
brute(0,0);
// for(auto x: hi){
// cout << " " << x;
// }
// cout << "\n";
cout << hi.size() << "\n";
}
return 0;
}