-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00417.cpp
More file actions
45 lines (34 loc) · 775 Bytes
/
Copy path00417.cpp
File metadata and controls
45 lines (34 loc) · 775 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
unordered_map<string, ll> dp;
string last;
void brute(ll now, ll d, string str){
if(now==d){
dp[str] = dp[last]+1;
last = str;
}
else{
for(char i = (str.length()==0)?'a': *(str.rbegin())+1; i <= 'z'; i++){
str += string(1, i);
brute(now+1, d, str);
str.pop_back();
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
last = ".";
dp["."] = 0;
for(ll i = 1; i <= 5; i++){
brute(0, i, "");
}
string str;
while(cin >> str){
cout << dp[str] << "\n";
}
return 0;
}