poj 1496 Word Index
2011-11-21 19:48
459 查看
WordIndex
TimeLimit:1000MS
MemoryLimit:10000K
TotalSubmissions:3586
Accepted:2030
Description
Encodingschemesareoftenusedinsituationsrequiringencryptionorinformationstorage/transmissioneconomy.Here,wedevelopasimpleencodingschemethatencodesparticulartypesofwordswithfiveorfewer(lowercase)lettersasintegers.
ConsidertheEnglishalphabet{a,b,c,...,z}.Usingthisalphabet,asetofvalidwordsaretobeformedthatareinastrictlexicographicorder.Inthissetofvalidwords,thesuccessivelettersofawordareinastrictlyascendingorder;thatis,laterlettersinavalidwordarealwaysafterpreviousletterswithrespecttotheirpositionsinthealphabetlist{a,b,c,...,z}.Forexample,
abcaepgwz
areallvalidthree-letterwords,whereas
aabarecat
arenot.
Foreachvalidwordassociateanintegerwhichgivesthepositionofthewordinthealphabetizedlistofwords.Thatis:
Yourprogramistoreadaseriesofinputlines.Eachinputlinewillhaveasinglewordonit,thatwillbefromonetofiveletterslong.Foreachwordread,ifthewordisinvalidgivethenumber0.Ifthewordreadisvalid,givetheword'spositionindexintheabovealphabeticallist.
Input
Theinputconsistsofaseriesofsinglewords,oneperline.Thewordsareatleastoneletterlongandnomorethatfiveletters.Onlythelowercasealphabetic{a,b,...,z}characterswillbeusedasinput.Thefirstletterofawordwillappearasthefirstcharacteronaninputline.
Theinputwillbeterminatedbyend-of-file.
Output
Theoutputisasingleinteger,greaterthanorequaltozero(0)andlessthanorequal83681.Thefirstdigitofanoutputvalueshouldbethefirstcharacteronaline.Thereisonelineofoutputforeachinputline.
SampleInput
SampleOutput
TimeLimit:1000MS
MemoryLimit:10000K
TotalSubmissions:3586
Accepted:2030
Description
Encodingschemesareoftenusedinsituationsrequiringencryptionorinformationstorage/transmissioneconomy.Here,wedevelopasimpleencodingschemethatencodesparticulartypesofwordswithfiveorfewer(lowercase)lettersasintegers.
ConsidertheEnglishalphabet{a,b,c,...,z}.Usingthisalphabet,asetofvalidwordsaretobeformedthatareinastrictlexicographicorder.Inthissetofvalidwords,thesuccessivelettersofawordareinastrictlyascendingorder;thatis,laterlettersinavalidwordarealwaysafterpreviousletterswithrespecttotheirpositionsinthealphabetlist{a,b,c,...,z}.Forexample,
abcaepgwz
areallvalidthree-letterwords,whereas
aabarecat
arenot.
Foreachvalidwordassociateanintegerwhichgivesthepositionofthewordinthealphabetizedlistofwords.Thatis:
a->1 b->2 . . z->26 ab->27 ac->28 . . az->51 bc->52 . . vwxyz->83681
Yourprogramistoreadaseriesofinputlines.Eachinputlinewillhaveasinglewordonit,thatwillbefromonetofiveletterslong.Foreachwordread,ifthewordisinvalidgivethenumber0.Ifthewordreadisvalid,givetheword'spositionindexintheabovealphabeticallist.
Input
Theinputconsistsofaseriesofsinglewords,oneperline.Thewordsareatleastoneletterlongandnomorethatfiveletters.Onlythelowercasealphabetic{a,b,...,z}characterswillbeusedasinput.Thefirstletterofawordwillappearasthefirstcharacteronaninputline.
Theinputwillbeterminatedbyend-of-file.
Output
Theoutputisasingleinteger,greaterthanorequaltozero(0)andlessthanorequal83681.Thefirstdigitofanoutputvalueshouldbethefirstcharacteronaline.Thereisonelineofoutputforeachinputline.
SampleInput
z a cat vwxyz
SampleOutput
26 1 0 83681
1:#include<iostream>
2:usingnamespacestd;
3:
4:__int64dp[16][32],sum[16],ans;
5:
6:intmain()
7:{
8:inti,j,len;
9:charstr[16];
10:
11:for(i=0;i<26;i++)
12:dp[0][i]=1;
13:for(i=1;i<10;i++){
14:for(j=25-i;j>=0;j--){
15:dp[i][j]+=dp[i][j+1];
16:dp[i][j]+=dp[i-1][j+1];
17:}
18:}
19:for(i=0;i<10;i++)
20:for(j=0;j<26;j++)
21:sum[i]+=dp[i][j];
22:
23: while(scanf("%s",str)!=EOF)
24: {
25: ans=0;
26: for(len=0;str[len];len++)
27: ans+=sum[len];
28: ans-=sum[len-1];
29: j=0;
30: for(i=len-1;i>=0;i--){
31: while(j<str[len-1-i]-'a'){
32: ans+=dp[i][j];
33: j++;
34: }
35: j++;
36: }
37: for(i=0;i<len-1;i++)
38: if(str[i]>=str[i+1])
39: ans=-1;
40: printf("%I64d\n",ans+1);
41: }
42:return0;
43:}
44:
45:
相关文章推荐
- POJ 1496 Word Index 笔记
- [ACM] poj 1496 Word Index(组合计数)
- POJ 1496 Word Index 和POJ 1850 Code 动态规划
- POJ 1496 Word Index
- [ACM] poj 1496 Word Index(组合计数)
- POJ 1496 Word Index 和POJ 1850 Code 动态规划
- POJ 题目1496 Word Index(排列组合)
- 排列组合:poj 1496 Word Index+poj 1850 Code
- [ACM] poj 1496 Word Index(组合计数)
- POJ 1850 Code/POJ 1496 Word Index(组合数学-字母串序号)
- (Relax 数论1.26)POJ 1496 Word Index(计算一个字符串在字典中的位置)
- POJ 1496 Word Index
- POJ 1496 Word Index
- POJ1496-Word Index
- poj1496—Word Index(组合数)
- POJ 1496 Word Index || POJ 1850 Code
- POJ1496-Word Index
- POJ 1496 Word Index (组合数学 求字符串对应编码)
- POJ 1850 Code POJ 1496 Word Index
- POJ 1850 Code POJ 1496 Word Index