這兩個(gè)題實(shí)際上是一樣的 后面一個(gè)數(shù)據(jù)范圍要大些
The coding system works like this:
? The words are arranged in the increasing order of their length.
? The words with the same length are arranged in lexicographical order (the order from the dictionary).
? We codify these words by their numbering, starting with a, as follows:
a - 1
b - 2
...
z - 26
ab - 27
...
az - 51
bc - 52
...
vwxyz - 83681
要求給出一個(gè)字符串讓你求出它的序號(hào)
以一個(gè)5位字符串為例
1 先求出1-4位所有字符串的個(gè)數(shù) 就是C(26,i);
2 再?gòu)脑?位字符串第二位開(kāi)始到最后一位 每位所取數(shù)字都在S[I-1]+1到S[I]-1之間,而后對(duì)后面幾位用組合數(shù)求個(gè)數(shù) 累計(jì)相加就是