-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00947v2.cpp
72 lines (59 loc) · 1.55 KB
/
00947v2.cpp
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
#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;
map<char, ll> freq;
void brute(ll depth, ll c, string temp = ""){
// cout << temp << " " << depth << " " << c << "\n";
if(c>cc) return;
else if(depth==a.length()){
if(c==cc) {
ll w = 0;
map<char, ll> freq2(freq);
for(ll i = 0; i < temp.length(); i++){
if(temp[i] != a[i] && freq2[temp[i]] > 0){
++w;
--freq2[temp[i]];
}
}
if(w == cw){
cout << temp << "\n";
hi.insert(temp);
}
}
}
else{
for(char g = '1'; g <= '9'; g++){
// cout << "a[" << depth << "] == " << g << " && freq[" << g << "] == " << freq[g] << "\n";
if(a[depth] == g && freq[g] > 0){
--freq[g];
brute(depth+1, c+1, temp+g);
++freq[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(), freq.clear();
cin >> a >> cc >> cw;
for(ll i = 0; i < a.length(); i++){
hm.insert(a[i]);
++freq[a[i]];
}
brute(0,0);
// for(auto x: hi){
// cout << " " << x;
// }
// cout << "\n";
cout << hi.size() << "\n";
}
return 0;
}