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. 初识ecside

    ecside,基于jsp tag的开源列表组件.支持导出pdf.xsl.csv等文件. 主要标签<ec:table>\<ec:row>\<ec:column>. 支 ...

  2. js 获取手机浏览器类型,修改css文件的class的值

    /*========================================= 函数功能:获取浏览器类型 =========================================*/ ...

  3. nyoj--114--某种序列(滚动数组)

    某种序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 数列A满足An = An-1 + An-2 + An-3, n >= 3  编写程序,给定A0, A1 和 ...

  4. Pycharm使用入门

    Python安装与Pycharm使用入门 一.安装Python 1.Linux下安装 一般系统默认已安装2.6.6版本,升级成2.7版本, 但 2.6 不能删除,因为系统对它有依赖,epel源里最新的 ...

  5. React 父组件触发子组件事件

    Parent组件 import React from "react"; import Child from "./component/Child"; class ...

  6. centos 出现的问题

    1.DNS问题,导致yum没得源 echo "nameserver 8.8.8.8">>/etc/resolv.conf 2.CentOS 7最小化安装后找不到‘ifc ...

  7. MVC中添加模块区域,并设置RedirectToAction跳转

    废话少说,直接上图:

  8. 使用DWR实现JS调用服务端Java代码

    DWR简介 DWR全称Direct Web Remoting,是一款非常优秀的远程过程调用(Remote Procedure Call)框架,通过浏览器提供的Ajax引擎实现在前端页面的JS代码中调用 ...

  9. SQL学习——基础语句(3)

    先上数据表 student表 grade 表 SQL Union 语句 合并两个或多个select查询结果集. select s_id from student union select  s_id ...

  10. Failed reading log event, reconnecting to retry

    数据库版本:5.6.16 系统:CentOS 6.5 搭建数据库从库报错:160411 14:30:39 [Note] Slave I/O thread: Failed reading log eve ...