Code

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 8256 Accepted: 3906



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

/**************************************
author : Grant Yuan
time : 2014/10/12 17:06
algortihm: 组合计数
source : POJ 1496 POJ 1850
***************************************/ #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
char a[27];
int num[27][27];
long long ans;
bool check()
{
int l=strlen(a);
if(l==1) return 1;
for(int i=0;i<l-1;i++)
if(a[i]>=a[i+1]) return 1;
return 0;
}
void Get_num()
{
int l=strlen(a);
for(int i=0;i<=26;i++)
for(int j=0;j<=i;j++)
{
num[i][j]=0;
if(i==0||j==0) num[i][j]=1;
else num[i][j]=num[i-1][j]+num[i-1][j-1];
}
}
void Get_sum1()
{
int l=strlen(a);
ans=0;
for(int i=0;i<l;i++)
ans+=num[26][i];
}
void Get_sum2()
{
int l=strlen(a);
for(int i=0;i<l;i++)
{
char j;
if(i==0) j='a';
else j=a[i-1]+1;
for(;j<a[i];j++)
{
ans+=num['z'-j][l-i-1];
}
}
}
int main()
{
Get_num();
while(~scanf("%s",a)){
int l;
l=strlen(a);
if(l==1) {printf("%d\n",a[0]-'a'+1);continue;}
if(check()) {printf("0\n");continue;}
Get_sum1();
Get_sum2();
printf("%lld\n",ans);
}
return 0;
}

POJ 1496 POJ 1850 组合计数的更多相关文章

  1. POJ 2249-Binomial Showdown(排列组合计数)

    Binomial Showdown Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18457   Accepted: 563 ...

  2. [总结]数论和组合计数类数学相关(定理&证明&板子)

    0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...

  3. bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)

    黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...

  4. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  5. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  6. 【BZOJ5491】[HNOI2019]多边形(模拟,组合计数)

    [HNOI2019]多边形(模拟,组合计数) 题面 洛谷 题解 突然特别想骂人,本来我考场现切了的,结果WA了几个点,刚刚拿代码一看有个地方忘记取模了. 首先发现终止态一定是所有点都向\(n\)连边( ...

  7. 【BZOJ5323】[JXOI2018]游戏(组合计数,线性筛)

    [BZOJ5323][JXOI2018]游戏(组合计数,线性筛) 题面 BZOJ 洛谷 题解 显然要考虑的位置只有那些在\([l,r]\)中不存在任意一个约数的数. 假设这样的数有\(x\)个,那么剩 ...

  8. 【BZOJ5305】[HAOI2018]苹果树(组合计数)

    [BZOJ5305][HAOI2018]苹果树(组合计数) 题面 BZOJ 洛谷 题解 考虑对于每条边计算贡献.每条边的贡献是\(size*(n-size)\). 对于某个点\(u\),如果它有一棵大 ...

  9. 【BZOJ3142】[HNOI2013]数列(组合计数)

    [BZOJ3142][HNOI2013]数列(组合计数) 题面 BZOJ 洛谷 题解 唯一考虑的就是把一段值给分配给\(k-1\)天,假设这\(k-1\)天分配好了,第\(i\)天是\(a_i\),假 ...

随机推荐

  1. 杭电(hdu)ACM 4548 美素数

    美素数 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submis ...

  2. 【iOS开发系列】XIB IBOutlets use strong or weak ?

    有人问.在ARC下,IBOutlets究竟应该定义成strong 还是 weak ?支持这个答案的人最多.答案仅是摘自官方文档的一个片段: From a practical perspective, ...

  3. 2015.04.28,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 36

    1. the great and the small 拉丁词语animus(mind的意思),animus和另一个拉丁词根anima(life principle.soul.spirit),是许多单词 ...

  4. poj--1236--Network of Schools(scc+缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14062   Accepted: 56 ...

  5. Maven + SpringMVC + Mybatis

    使用IDEA配置Maven + SpringMVC + Mybatis [一步一步踩坑详细配置完成] PS:初学,想使用Maven配置一个SpringMVC的开发环境,照着网上的各种图文解说,配置了好 ...

  6. CXF2.7.7 java.lang.RuntimeException: Cannot create a secure XMLInputFactory

    cxf-2.7.7.jar neethi-3.0.2.jar stax2-api-3.1.1.jar woodstox-core-asl-4.2.0.jar wsdl4j-1.6.3.jar xmls ...

  7. http server优雅启停原理及验证

    问题背景 在 http应用程序重启时,如果直接 kill -9 使程序退出,然后再启动,会存在的问题: 旧的请求未处理完,如果服务端进程直接退出,会造成客户端连接中断(收到 RST) 新请求打过来,服 ...

  8. Android 长按识别图中二维码 zxing

    #基于 Zxing, 初学Android 代码质量不高 //长按,通过zxing读取图片,判断是否有二维码 bigImage.setOnLongClickListener(new View.OnLon ...

  9. Android 多线程下载 显示进度 速度

    功能要求:从网络下载一APK应用,显示下载速度.进度,并安装应用. 运行效果图: 工程结构图: 很简单,就一个activity,一个更新UI的线程,一个下载线程加个文件处理类 主要代码: /** *多 ...

  10. Mysql command not found on mac pro

    export PATH=${PATH}:/usr/local/mysql/bin If you want this to be run every time you open terminal put ...