编码
题目链接:https://www.luogu.com.cn/problem/P1246
题意:
a=1,b=2......,z=26,ab=27,ac=28
思路:
DFS按顺序枚举所有的单词编码,存在哈希表中查询
dfs具体需要枚举单词长度,按照单词长度为关键字搜索
int cnt;
map<string,int>mp;
string now;
void dfs(int len,int k){
if(k>=len){
// if(len==2)debug(now);
mp[now]=++cnt;return;
}
char st;
if(k==0)st='a';
else st= now[k-1];
for(int j= (k==0)?(st-'a'):(st-'a'+1);j<26;j++){
now[k]=(char)('a'+j);
dfs(len,k+1);
}
}
void solve(){
for(int len=1;len<=6;len++){
now.clear();
now.resize(len);
dfs(len,0);
}
string s;cin>>s;
cout<<mp[s]<<endl;
}

浙公网安备 33010602011771号