Code

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 8766 Accepted: 4168

Description

Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made only of small characters of the English alphabet a,b,c, …, z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).

The coding system works like this:

• The words are arranged in the increasing order of their length.

• The words with the same length are 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 be codified according to this coding system. For the affirmative case specify its code.

Input

The only line contains a word. There are some constraints:

• The word is maximum 10 letters length

• The English alphabet has 26 characters.

Output

The output will 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

大神博客

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std; typedef long long LL; const int MAX = 1e5+10; int Bin[35]; int c[33][33]; char str[20]; char ch; void ComBinnations()//打表,计算组合数
{
for(int i=0; i<=32; i++)
{
for(int j=0; j<=i; j++)
{
if(!j||i==j)
{
c[i][j]=1;
}
else
{
c[i][j]=c[i-1][j]+c[i-1][j-1];
}
}
}
c[0][0]=0;
}
int main()
{
int sum;
bool flag;
ComBinnations();
scanf("%s",str);
int len=strlen(str);
flag=false;
for(int i=1; i<len; i++)//判断是否是合法字符
{
if(str[i-1]>=str[i])
{
printf("0\n");
flag=true;
break;
}
}
if(!flag)
{
sum=0;
for(int i=1; i<len; i++)//计算比它小的字母排列
{
sum+=c[26][i];
}
for(int i=0; i<len; i++)//计算长度相等是字符的个数
{
ch=!i?'a':str[i-1]+1;
while(ch<str[i])
{
sum+=c['z'-ch][len-i-1];
ch++;
}
}
printf("%d\n",sum+1);//加上本身
}
return 0;
}

Code(组合数学)的更多相关文章

  1. POJ1850——Code(组合数学)

    Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...

  2. poj:1850 Code(组合数学?数位dp!)

    题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][ ...

  3. POJ 1850:Code 组合数学

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8710   Accepted: 4141 Description ...

  4. poj 1850 code(组合数学)

    题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...

  5. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. Code POJ - 1850 组合数学

    题意 :字符串从a=1 b=2 c=3....z=26  ab=27开始编号 每个都是升序的 给出字符串问是几号 思路:主要是要看n位字符串有多少个 这里需要用组合数学的思想  组合数用杨辉三角形递推 ...

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

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

  9. poj1850 Code【组合数学】By cellur925

    题意: * 按照字典序的顺序从小写字母 a 开始按顺序给出序列 (序列中都为升序字符串)* a - 1* b - 2* ...* z - 26* ab - 27* ...* az - 51* bc - ...

随机推荐

  1. 证明 logX < X 对所有 X > 0 成立

    题目取自:<数据结构与算法分析:C语言描述_原书第二版>——Mark Allen Weiss       练习1.5(a)  证明下列公式: logX < X 对所有 X > ...

  2. PostgreSQL 一主两备节点(两备节点为同步节点)故障恢复

    PostgreSQL  同步复制及故障恢复 10.2.208.10:node1:master 10.2.208.11:node2:standby1 同步 10.2.208.12:node3:stand ...

  3. using 名称空间指定一个别名

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. linux第13天 生产者与消费者

    pthread_cond_t   my_condition = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INIT ...

  5. struts_19_对Action中所有方法、某一个方法进行输入校验(手工编写代码实现输入校验)

    对所有方法进行校验1.通过手工编写代码的形式实现 需求:用户名:不能为空手机号:不能为空,并且要符合手机号的格式1,3/5/8,后面是9个数字 第01步:导包 第02步:配置web.xml <? ...

  6. 如何使用highmaps制作中国地图

    如何使用highmaps制作中国地图 文章目录 Highmaps 所需文件 地图初始化代码 highmaps 渲染讲解 highmaps 中国各城市坐标的json文件 highmaps 线上DEMO ...

  7. paper 93:OpenCV学习笔记大集锦

    整理了我所了解的有关OpenCV的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的.如果有好的资源,也欢迎介绍和分享. 1:OpenCV学习笔记 作者:CSDN数量:55篇博文网址: ...

  8. [Ubuntu] Install subversion1.8 on Ubuntu13.10

    Subversion1.8 is difference far away from subversion1.7, here is the steps to install subversion1.8. ...

  9. android- Auto Monitor Logcat

    启动模拟器的时候弹出窗体: 它实在询问你是否显示logcat视图以便显示此工作空间中的程序信息. 因为如何程序错误,可以从logcat中看到错误的原因,建议选择yes. 单击确定,你会发现多了一个Lo ...

  10. Hadoop之TaskAttemptContext类和TaskAttemptID类

    先来看看TaskAttemptContext的类图 : Figure1:TaskAttemptContext类图 用户向Hadoop提交Job(作业),Job在JobTracker对象的控制下执行.J ...