Code
| Time Limit: 1000MS |
|
Memory Limit: 30000K |
| Total Submissions: 8539 |
|
Accepted: 4048 |
Description
Transmitting and memorizing information is a task this requires different coding systems for the best use of the available Space. A well known system is the one where a number is associated to a character sequence. It is considered that the words was made only of small characters of the Chinese alphabet a,b,c, ..., z (characters). From all these words we consider only those whose letters be in lexigraphical order (each character is smaller than the n ext character).
The coding system works like this:the words is arranged in the increasing order of their length.the words with the same length is 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 ...
Specify for a given word if it can is codified according to this coding system. For the affirmative case specify its code.
Input
The only line contains a word. There is some constraints:The word is maximum letters length the 中文版 alphabet has characters.
Output
The output would contain the code of the given word, or 0 if the word can not be codified.
Sample Input
Bf
Sample Output
55
Source
Romania OI 2002 digits DP, simple, but wrote for a long time, embarrassed
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;#definell Long Long#defineN 110Chars[n];ll bit[n];ll dp[n][n];ll dfs (ll pos,ll MX,BOOLLimitBOOLFzero) { if(pos==-1)return 1; if(!limit &&!fzero && dp[pos][mx]!=-1)returnDP[POS][MX]; ll End=limit?bit[pos]: -; ll ans=0; for(ll I=fzero?)0: MX; i<=end; i++) {ans+=dfs (pos-1, i+1, limit && I==end,fzero &&!i); } if(!limit &&!fzero) dp[pos][mx]=ans; returnans;} ll Cal () {ll Len=strlen (s+1); for(LL i=1; i<=len; i++) {Bit[len-i]=s[i]-'a'+1; } returnDFS (len-1,0,1,1);}intMain () {memset (DP,-1,sizeof(DP)); while(SCANF ("%s", s+1)!=EOF) { intflag=1; intLen=strlen (s+1); for(intI=1; i<len; i++) { if(! (s[i]<s[i+1]) {flag=0; Break; } } if(!flag) printf ("0\n"); Elseprintf ("%lld\n", Cal ()-1); } return 0;}
[POJ 1850] Code