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. sqlite学习笔记7:C语言中使用sqlite之打开数据库

    数据库的基本内容前面都已经说得差点儿相同了.接下看看如何在C语言中使用sqlite. 一 接口 sqlite3_open(const char *filename, sqlite3 **ppDb) 打 ...

  2. oracle经常使用函数(2)

    1.TRIM([ { { LEADING | TRAILING | BOTH }[ trim_character ]| trim_character} FROM ]trim_source) 函数 參数 ...

  3. remote debug

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging https://docs.microsoft.com/e ...

  4. lightoj--1410--Consistent Verdicts(技巧)

    Consistent Verdicts Time Limit: 5000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Su ...

  5. NEU 1040 Count

    1040: Count 时间限制: 1 Sec  内存限制: 128 MB提交: 59  解决: 23[提交][状态][讨论版] 题目描述 Many ACM team name may be very ...

  6. 对python变量的理解

    #!/usr/bin/python class Person: '''some words content or descriptions!''' name='luomingchuan' _age = ...

  7. idea设置Template

    在eclipse里面经常会用到syso和main类似这样的内容,但是idea工具里面没有,可以通过 Editor ==> Live templates  ==> 1.首先创建一个自己的Te ...

  8. 主流的Python领域和框架--转

    原文地址:https://www.zhihu.com/question/19899608

  9. shopping car 3.0

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @File : 购物车3.0.py# @Author: Anthony.waa# @Date : 2018/ ...

  10. ZBrush中自动保存在哪里

    在使用 ZBrush®执行任何会话期间,您都可以设置将文件自动保存,并可以修改保存时间间隔,文件保存位置等设置.发生系统错误后要重新启动ZBrush时,可以从临时文件夹或指定的文件夹中恢复备份文件.如 ...