-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1339.cpp
More file actions
55 lines (55 loc) · 1.04 KB
/
1339.cpp
File metadata and controls
55 lines (55 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
int arr[10];
int isFilled[11];
vector<string> v;
int res=0;
void calc() {
int ret=0;
for(auto it:v){
int temp=0;
for(auto c:it){
temp=temp*10+arr[c-'A'];
}
ret+=temp;
}
res=max(res,ret);
}
void f(int phase){
if(phase==10){
calc();
return;
}
for(int i=1; i<=10; ++i){
if(isFilled[i]) continue;
isFilled[i]=1;
arr[phase]=i-1;
f(phase+1);
isFilled[i]=0;
}
}
int main(){
int N; cin>>N;
set<char> ref;
vector<string> temp;
for(int i=0; i<N; ++i){
string str; cin>>str;
for(auto it:str) ref.insert(it);
temp.push_back(str);
}
map<char,char> m;
char ch='A';
for(auto it = ref.begin(); it!=ref.end(); ++it){
m[*it]=ch;
ch++;
}
for(auto it:temp){
string newStr="";
for(auto c:it){
newStr.push_back(m[c]);
}
v.push_back(newStr);
}
f(0);
cout << res << '\n';
}