组合数学。。。。和上一题是一样的。。。。
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. Newtonsoft.Json动态过滤属性

    Newtonsoft.Json动态过滤属性 接口写的多了,会发现很多的问题.同一个dto,不同的action返回的字段个数不一样.往往开发人员因为懒或者各种原因一股脑的全返回,会浪费很多流量且用户体验 ...

  2. Alpha版本十天冲刺--Day4

    站立式会议 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 解决线程信息传递问题(使用函数回调),Android登录验证接口完善 无 json解析,忘记密码界面验证码获取接口,忘记密码请求 ...

  3. Django 部署 uwsgi + nginx + supervisor

    Django 部署 uwsgi + nginx + supervisor https://hacpai.com/article/1460607620615?p=1&m=0 zonghua • ...

  4. BZOJ4446: [Scoi2015]小凸玩密室

    用ui,j表示走完i的子树后走到i的深度为j的祖先的兄弟的最小代价: 用vi,j表示走完i的子树后走到i的深度为j的祖先的最小代价,用u算出v. 枚举起点,计算答案. #include<bits ...

  5. js网页如何获取手机屏幕宽度

    function a(){"屏幕宽高为:"+screen.width+"*"+screen.height:}其它:网页可见区域宽:document.body.c ...

  6. uC/OS-II应用程序代码

    /*************************************************************************************************** ...

  7. MySQL学习笔记——约束

    1.约束是在表上强制执行的数据检验规则,约束主要用于保证数据库的完整性. 2.当表中数据有相互依赖性时,可以保护相关的数据不被删除. 3.大部分数据库支持下面五类完整性约束: - NOT NULL非空 ...

  8. [原创]用“人话”解释不精确线搜索中的Armijo-Goldstein准则及Wolfe-Powell准则

    [原创]用“人话”解释不精确线搜索中的Armijo-Goldstein准则及Wolfe-Powell准则 转载请注明出处:http://www.codelast.com/ line search(一维 ...

  9. Behavior Tree

    http://www.craft.ai/blog/bt-101-behavior-trees-grammar-basics/ https://github.com/libgdx/gdx-ai/wiki ...

  10. 配置git密钥,然后新建仓库

    Generating SSH keys (打开下面的链接) https://help.github.com/articles/generating-ssh-keys/ 完成配置后 开始在github上 ...