Coordinates make me dizzy. I first typed a table to store the number of solutions with a letter starting with I. Then, it is decomposed from the input string:
Assume that it is a cdvx string, and add the number of all solutions with a length of 1, 2, and 3, and then analyze from the right. The first character c must be at least a, and, the number of solutions starting with B is 4. The minimum length of the second character must be 'C' + 1, that is, d ', so we need '~ The number of schemes whose names start with 'U' is 2 is the same as that of the last one.
Here we should know how to solve the problem. Some people say this is Yang Hui's triangle. It is really Yang Hui's triangle to output the table-making results, but the practice is the same.
Code:
[Cpp]
# Include <iostream>
Using namespace std;
Int dp [30] [30], cnt [30]; // dp is the number of I schemes starting with a character, and cnt is the number of all schemes whose length is I.
Int main ()
{
Int I, j, k, sum, temp;
For (I = 1; I <= 26 & (dp [1] [I] = 1); I ++ );
Cnt [1] = 26;
For (I = 2, sum = 26; I <= 26; I ++ ){
Temp = 0;
For (j = 1; j <= 27-i; j ++ ){
Sum-= dp [I-1] [j];
Dp [I] [j] = sum;
Temp + = sum;
} Www.2cto.com
Sum = temp; cnt [I] = sum;
}
Char str [15];
While (scanf ("% s", str )! = EOF ){
Sum = 0;
Bool flag = true;
Int len = strlen (str );
For (I = 1; I <len; I ++ ){
If (str [I]-str [I-1] <= 0) {// determines if there is any descending order
Flag = false; break ;}
Else sum + = cnt [I];
}
If (flag ){
For (I = 0; I <len; I ++) {// solve the problem by Analysis
J = (I = 0? 1: str [I-1]-'A' + 2 );
For (; j <= str [I]-'A'; j ++)
Sum + = dp [len-I] [j];
}
Printf ("% d \ n", sum + 1 );
}
Else
Printf ("0 \ n ");
}
Return 0;
}