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. LeetCode_18 4Sum

    Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums s ...

  2. 封装一个获取module.exports内容的方法

    let fs = require('fs') let req = (moduleName) => { //content代表的是文件内容 let content = fs.readFileSyn ...

  3. 电子笔记本的思考(1)(ver0.2)

    章节:电子笔记本的思考(1)   陶哲轩在<解题·成长·快乐——陶哲轩教你学数学>中着重强调,用纸笔来“缓存”思维对于数学解题的重要性: 用选定的符号表达你所知道的信息,并画一个示意图.把 ...

  4. docker 部署spring.boot项目【一】(引用外部配置文件)

    上一篇随笔,nginx是启动运行在容器内,spring.boot的web项目是运行在宿主内,这一篇的目的,是把web项目也制作成镜像,然后在容器里启动. 文件目录结构如下: 主要文件结构说明:(1)b ...

  5. jsp页面应用简记

    1.记录总数据条数 <div class="" > <span class="">共有数据:<strong>${fn:len ...

  6. 运行/调试你的PHP代码

    前言 没有任何一名程序员可以一气呵成.完美无缺的在不用调试的情况下完成一个功能或模块.调试实际分很多种情况.本篇文章我分享下自己在实际开发工作中的经验,我个人理解,调试分三种,注意我所讲的是调试并非测 ...

  7. 如何通过js在子页面调用父页面元素的click事件

    //获取父页面的某个元素var node = window.parent.document.getElementById("btnReturn");//调用该元素的Click事件 ...

  8. 【Codeforces 466B】Wonder Room

    [链接] 我是链接,点我呀:) [题意] 让你把长为a,宽为b的房间扩大(长和宽都能扩大). 使得它的面积达到6*n 问你最小的能满足要求的面积是多少 输出对应的a和b [题解] 假设a< b ...

  9. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores

    #1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...

  10. RabbitMQ-rabbitmqctl和插件使用(四)

    rabbitmqctl 说明 进入mq的bin目录 cd /usr/local/Cellar/rabbitmq/3.7.8/sbin ./rabbitmqctl [-n node] [-t timeo ...