组合数学。。。。和上一题是一样的。。。。
Word Index
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4303 Accepted: 2439

Description

Encoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five or fewer (lower case) letters as integers.

Consider the English alphabet {a,b,c,...,z}. Using this alphabet, a set of valid words are to be formed that are in a strict lexicographic order. In this set of valid words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always after previous letters with respect to their positions in the alphabet list {a,b,c,...,z}. For example,

abc aep gwz

are all valid three-letter words, whereas

aab are cat

are not.

For each valid word associate an integer which gives the position of the word in the alphabetized list of words. That is:

a -> 1
b -> 2
.
.
z -> 26
ab -> 27
ac -> 28
.
.
az -> 51
bc -> 52
.
.
vwxyz -> 83681
Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is invalid give the number 0. If the word read is valid, give the word's position index in the above alphabetical list. 

Input

The input consists of a series of single words, one per line. The words are at least one letter long and no more that five letters. Only the lower case alphabetic {a,b,...,z} characters will be used as input. The first letter of a word will appear as the first character on an input line.

The input will be terminated by end-of-file.

Output

The output is a single integer, greater than or equal to zero (0) and less than or equal 83681. The first digit of an output value should be the first character on a line. There is one line of output for each input line.

Sample Input

z
a
cat
vwxyz

Sample Output

26
1
0
83681

Source

East Central North America 1995

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int c[30][30];
char str[12];

void Init()
{
    for(int i=0;i<30;i++)
        c[0]=c=1;
    for(int i=2;i<30;i++)
        for(int j=1;j<i;j++)
            c[j]=c[i-1][j-1]+c[i-1][j];
}

int main()
{
    Init();
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        bool flag=true;
        for(int i=0;i<len-1;i++)
        {
            if(str>=str[i+1])
            {
                flag=false;
                break;
            }
        }
        if(flag==false)
        {
            puts("0");
            continue;
        }
        ///n-1...1
        int sum=0;
        for(int i=1;i<len;i++)
            sum+=c[26];
        ///n
        for(int i=0;i<len;i++)
        {
            char ch=(i==0)?'a':str[i-1]+1;
            while(ch<str)
            {
                sum+=c['z'-ch][len-1-i];
                ch++;
            }
        }
        printf("%d\n",++sum);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 1496 Word Index的更多相关文章

  1. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  2. 组合数学poj 1496 1850 同样的代码过两题

    Description   1942 Transmitting and memorizing information is a task that requires different coding ...

  3. poj 1850/poj 1496

    http://poj.org/problem?id=1850 -----------------http://poj.org/problem?id=1496 两题解法类似..本题为组合数学的题,要求所 ...

  4. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  5. poj 1204 Word Puzzles(字典树)

    题目链接:http://poj.org/problem?id=1204 思路分析:由于题目数据较弱,使用暴力搜索:对于所有查找的单词建立一棵字典树,在图中的每个坐标,往8个方向搜索查找即可: 需要注意 ...

  6. [POJ 1204]Word Puzzles(Trie树暴搜&amp;AC自己主动机)

    Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...

  7. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  8. POJ 1496

    #include <iostream> #include <string> using namespace std; int fac(int num); int C(int n ...

  9. poj1496 Word Index / poj1850 Code(组合数学)

    poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...

随机推荐

  1. hihoCoder 1401 Registration

    多队列模拟. 与POJ #1025 Department类似, 不过简化很多. 貌似这类模拟题经常出现. 用STL中的优先队列 (priority_queue<>) 很好写. 这题我写得很 ...

  2. Beta Daily Scrum 第六天

    [目录] 1.任务进度 2.困难及解决 3.燃尽图 4.代码check-in 5.总结 1. 任务进度 学号 今日完成 明日完成 612 昨天完成任务,今天看有没有bug,找一找 好像没什么事 615 ...

  3. BZOJ1798: [Ahoi2009]Seq 维护序列seq

    传送门 写这道题是为了get一个同时传送乘法下标和加法下标的小技巧,线段树模板题.不多说. 标记名字打错无限智力-- //BZOJ 1798 //by Cydiater //2016.9.13 #in ...

  4. hibernate......1、2级缓存

    1.什么是缓存? 缓存是介于物理数据源与应用程序之间,是对数据库中的数据复制一份临时放在内存中的容器,其作用是为了减少应用程序对物理数据源访问的次数,从而提高了应用程序的运行性能.Hibernate在 ...

  5. Git创建ssh-key

    打开git bash界面,输入: ssh-keygen -t rsa -C "yourname@email.com" 一路回车,后续保持默认值即可. 把C:\users\yourn ...

  6. gitlab迁移库地址后远程的切换

    本地需要把origin删除,然后再添加新的origin git remote rm origingit remote add origin [url] git push --set-upstream ...

  7. Ajax异步刷新,测试用户名是否被注册

    <body> <form name="form_register"> <input type="> <input type=&q ...

  8. hibernate实现有两种配置,xml配置与注释配置。

    (1):xml配置:hibernate.cfg.xml (放到src目录下)和实体配置类:xxx.hbm.xml(与实体为同一目录中) <?xml version='1.0' encoding= ...

  9. jsp action中附件下载的写法

    //一些主要的包和类 import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java ...

  10. Foundation框架--字典( NSDictionary NSMutableDictionary )

    基础知识 1.字典不允许相同的key,但允许有相同的value. 2,字典是无序的,字典不能排序. 3.字典里的内容是成对存在的,不会出现单数. 4.快速创建的方式只适合不可变字典. 不可变字典 #i ...