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. 朴素的UNIX之-调度器细节

    0.多进程调度的本质 我们都知道UNIX上有一个著名的nice调用.何谓nice,当然是"好"了.常规的想法是nice值越大越好,实际上,nice值越好,自己的优先级越低.那么为何 ...

  2. c语言数组小谈

    #include <stdio.h> #include <stdlib.h> #define N 5 int main() { double score[5]; int i; ...

  3. 转:Centos 7 使用git 用 ssh 连接github服务器

    https://blog.csdn.net/wzq793957419/article/details/68067204 首先Linux下载git,ssh服务都弄好 生成ssh密钥: $ ssh-key ...

  4. WebRTC开源项目一览之二

    .Kurento视频直播系统4.1  应用实例搞视频会议就会涉及一对多.多对多.广播.转码.混音.合屏.录制,这就需要用到流媒体服务器,而kurento就具有这些功能.他主要用来作为webrtc的流媒 ...

  5. 29.QT主窗口加widget

    运行效果 widget布局showwidget.h #ifndef SHOWWIDGET_H #define SHOWWIDGET_H #include <QWidget> #includ ...

  6. 在ubuntu下安装redis

    最简单在线安装的方式: #安装Redis服务器端 ~ sudo apt-get install redis-server 安装完成后,Redis服务器会自动启动,我们检查Redis服务器程序 # 检查 ...

  7. SQLSERVER 链接服务器

    1. 执行代码 EXEC sp_addlinkedserver @server='XLZFSqlServer', --链接服务器别名 @srvproduct='', @provider='SQLOLE ...

  8. jQuery在多个div中,删除指定项

    之前工作中有一个需求,就是在一堆图片列表中,点击具体的图片,并从界面移除:点击具体的图片,下载:这是一个思路 <style type="text/css" media=&qu ...

  9. android 给imageView,文字等加上阴影[记录]

    1.链接 https://github.com/Devlight/ShadowLayout 2.效果 3.code compile 'com.github.devlight.shadowlayout: ...

  10. onTouchEvent事件

    @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTIO ...