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. Bullet:ORACLE Using SQL Plan Management(一)

    SQL Plan Management如何工作? 当一个SQL硬解析时,基于成本的优化器CBO会生成多个执行计划,并从这些执行计划中选择一个优化器认为最低成本的执行计划. 如果SQL plan bas ...

  2. Radar Installation POJ - 1328 (贪心)

    题目大意(vj上的翻译版本) 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的 ...

  3. 数据结构---链表ADT C++实现

    最近在学习数据结构,刚开始一直在看书,但是总是感觉似懂非懂,心想还不如自己操练一波,势必有所收获.现将实现代码发表此地,以备日后复习,若有错误或者建议,欢迎告知本人! 1. 节点类 class Nod ...

  4. 输入框点击下滑Ztree菜单

    记录一个功能实现代码,我这边前端用的是layui,需要实现的效果如下: 需求:当点击选择地区的时候会出现如上图的下拉菜单. 分析:首先肯定给这个输入框加监听,click方法,然后将ztree的div显 ...

  5. type、object、class之间的关系

    class Foo: pass print(type(int)) # <class 'type'> print(type(str)) # <class 'type'> prin ...

  6. Django REST framework 数据处理api

    一.url分发 以防有其他业务线的需要,导致url杂乱,将每个app用到的url都设置在自己的应用中. # 项目下的url url(r"^api/(?P<version>\w+) ...

  7. HTTP服务和APACHE

    HTTP服务和APACHE 1. 跨Internet的主机间通讯 要通过Internet进行通信,至少需要一对套接字:其中一个运行在客户端,定义了一个唯一的客户进程,称之为ClientSocket,另 ...

  8. eclipse自动换行

    Eclipse是一款非常优秀的IDE,但是不能自动换行,需要安装一个插件完成这个功能. 安装办法有两种: 1.在线安装. 选择help-->install new software,点击Add, ...

  9. buf.readUInt32BE()函数详解

    buf.readUInt32BE(offset[, noAssert]) buf.readUInt32LE(offset[, noAssert]) offset {Number} 0 noAssert ...

  10. python之cookbook-day03

    第一章:数据结构和算法 1.3 保留最后 N 个元素 问题: 在迭代操作或其他操作的时候,怎样只保留最后有限几个元素的历史记录? 解决方案: 保留有限历史记录正是 collections.deque ...