您的位置:首页 > 其它

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:

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:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: