Code
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 9918   Accepted: 4749

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

 
/*
组合数
题意是查一个字串的字典序排名
先求出长度比它小的,显然是ΣC 26 i(i<len)
然后求出长度等于它却比它小的。具体看代码。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 27 using namespace std;
int c[N][N],ans;
char str[N]; inline void combination()
{
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
if(!j || i==j)
c[i][j]=;
else
c[i][j]=c[i-][j-]+c[i-][j];
c[][]=;
return;
} int main()
{
combination();
while(cin>>str)
{
ans=;
int len=strlen(str);
for(int i=;i<len;i++)
if(str[i]<=str[i-])
{
cout<<""<<endl;
return ;
}
for(int i=;i<len;i++) ans+=c[][i];//长度小于它的所有方案
for(int i=;i<len;i++)
{
char ch=(!i)?'a':str[i-]+;//比上一个大
while(ch<str[i])//比当前这个小
{
ans+=c['z'-ch][len-i-];//长度等于它且排在它前面的所有方案
ch++;
}
}
cout<<++ans<<endl;
}
return ;
}

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

  1. poj 3252 组合数

        主要考察组合数知识,初始化的时候参考公式 首先先推个公式,就是长度为len的Round Numbers的个数.      长度为len,第一位肯定是1了.      那么后面剩下 len-1位 ...

  2. POJ Code the Tree 树的pufer编号

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2259   Accepted: 859 Desc ...

  3. Code (组合数)

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7184   Accepted: 3353 Description Trans ...

  4. POJ 1850 Code(组合数)

    http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...

  5. POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数

    http://poj.org/problem?id=3904   题意:给一些数,求在这些数中找出四个数互质的方案数.   莫比乌斯反演的式子有两种形式http://blog.csdn.net/out ...

  6. POJ 3904 Sky Code (容斥原理)

    B - Sky Code Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  7. POJ 1942 Paths on a Grid(组合数)

    http://poj.org/problem?id=1942 题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 . 思路 : ...

  8. [欧拉回路+手动开栈] poj 1780 Code

    题目链接: http://poj.org/problem? id=1780 Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  9. POJ - 1850 B - Code

    Transmitting and memorizing information is a task that requires different coding systems for the bes ...

随机推荐

  1. javaScript--进阶1--数据类型、操作符

    一.JS基础知识背景 1.1 弱类型脚本语言 脚本语言是:弥补编译语言的不足而存在的,作为补充语言,不用编译,解析一行执行一行. 弱类型语言:简单理解定义一个变量,可以有多种数据类型.(var tem ...

  2. css--小白入门篇5

    一.行高和字号 1.1 行高 CSS中,所有的行,都有行高.盒模型的padding,绝对不是直接作用在文字上的,而是作用在“行”上的. 1 line-height: 40px; 文字,是在自己的行里面 ...

  3. Linux之sed:删除某行以及替换

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为:         sed ...

  4. Nginx + Lets'encrypt 实现HTTPS访问七牛空间资源

    上一篇文章 为七牛云存储空间绑定自定义域名,并使用七牛云提供的免费SSL证书,将自定义加名升级为HTTPS 我们提到利用七牛的免费SSL证书,将自定义加名升级为HTTPS的方法. 不知道有没有小伙伴会 ...

  5. 有哪些可以节省chrome内存的扩展插件?

    不知道从什么时候开始,chrome浏览器就这样不知不觉的超过IE浏览器成为全球第一大浏览器.我们在赞赏chrome浏览器流畅的速度时,更多的是对其chrome插件功能的赞赏.但是我们也发现了一个致命的 ...

  6. 3.2.2.5 BRE运算符优先级

        在数学表达式里,正则表达式的运算符具有某种已定义的优先级,指的是某个运算符(优先级较高)将比其他运算符先被处理.       BRE运算符优先级,由高至低   运算符 表示含义 [..] [= ...

  7. 【Codeforces 242C】King's Path

    [链接] 我是链接,点我呀:) [题意] 让你找到(x0,y0)到(x1,y1)的一条最短路 走过的点必须在所给的n个横向路径上 [题解] 因为n条横向路径上的点最多不会超过10的5次方个,所以我们可 ...

  8. 疫情控制(codevs 1218)

    题目描述 Description H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都, 也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为 ...

  9. 过河(codevs 1155)

    题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥 ...

  10. VNC Viewer 设置屏幕分辨率-解决屏幕分辨率问题

    https://blog.csdn.net/runningtortoises/article/details/51425332