Title Link: http://acm.swust.edu.cn/problem/715/
Time limit (ms): $ Memory Limit (KB): 65535 in data encryption and data compression, special strings are often required to be encoded. The given Alphabet a consists of 26 lowercase English letters a={a,b,..., Z}. The ascending string produced by the alphabet refers to the same order in which letters appear from left to right in the same order as letters appear in the alphabet, and each character appears up to 1 times. For example, strings such as a,b,ab,bc,xyz are ascending strings. All ascending strings that are not more than 6 of the length of the alphabet A are now sorted in dictionary order and encoded as follows.
1 2 ... 26 27 28 ...
A b ... z ab AC ...
For a given length of not more than 6 of the ascending string, the program calculates its encoding in the above dictionary. The first line of the description file is a positive integer k, which indicates a total of k rows next.
In the next K-line, each line is given a string. Input has a total of k rows, each of which corresponds to the encoding of a string. Output
Sample Input
Sample Output Problem Solving ideas: This problem with the digital DP words are not too realistic (state design too weird to say ~ ~ ~) so the designation of a letter only one arrangement of the legal, consistent with the concept of combined number, you can consider using the combined number and then in the current state, the length is less than the total number of Len, equal to L The total number of the current sequence of en (equivalent to the problem refinement) specific look at the code bar ~ ~ ~ Worth noting is the use of Yang Hui triangle calculation combination number and composite properties cur[i][j]=cur[i][i-j]; The code is as follows:
1#include <iostream>2#include <cstring>3 using namespacestd;4 5 Chars[7];6 intcur[ -][ -] = {1 };7 8 //pre-processing using Yang Hui triangle calculation combination number9 voidinit () {Ten intI, left, right; One for(i =1; I <= -; i++){ Acur[i][0] = Cur[i][i] =1; -left =1, right = i-1; - while(Left <=Right ) { theCur[i][left] = cur[i-1][left-1] + cur[i-1][left]; -cur[i][right--] = cur[i][left++];//Combinatorial number properties cur[i][j]=cur[i][i-j]; - } - } + } - + //the number of strings that are shorter than Len A intMinlen_num (intLen) { at intI, CNT =0; - for(i =1; i < Len; i++) -CNT + = cur[ -][i]; - returnCNT; - } - in //the number of the current string in front of the current length - intEnquallen_num (intLen) { to intI, j, cnt =0, Pre =-1, TMP; + for(i =0; i < Len; i++){ -TMP = S[i]-'a'; the for(j = Pre +1; J < tmp; J + +) *CNT + = cur[ --J-1][len-i-1]; $Pre =tmp;Panax Notoginseng } - returnCNT; the } + A BOOLJudgeintLen) { the for(inti =1; i < Len; i++) + if(S[i] <= s[i-1]) - return false; $ return true; $ } - - intMain () { the init (); - intT, CNT, Len;WuyiCIN >>T; the while(t--){ -CNT =0; WuCIN >>s; -Len =strlen (s); About if(!judge (len)) cout <<0<<Endl; $ Else{ -CNT + =Minlen_num (len); -CNT + =Enquallen_num (len); -cout << CNT +1<<Endl; A } + } the return 0; -}
View Code
Swust OJ 715--dictionary order problem (combined number preprocessing)