Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 7184   Accepted: 3353

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

忽略了输出0的情况,wa了若干次。。。
 #include<stdio.h>
#include<string.h>
int c[][]; void init()
{
memset(c,,sizeof(c));
for(int i = ; i <= ; i++)
{
c[i][] = ;
c[i][i] = ;
} for(int i = ; i <= ; i++)
{
for(int j = ; j < i; j++)
{
c[i][j] = c[i-][j-] + c[i-][j];
}
}
} int main()
{
init();
int i,j,sum;
char s[];
scanf("%s",s);
int len = strlen(s); int flag = ;
for(i = ; i < len; i++)
{
for(j = i+; j < len; j++)
{
if(s[i] >= s[j])
{
flag = ;
break;
}
}
if(flag == )
break;
}
if(flag == )
printf("0\n");
else
{
sum = ;
for(i = ; i <= len-; i++)
sum += c[][i]; for(j = ; j <= s[]-'a'-; j++)
sum += c[-j][len-]; for(i = ; i < len; i++)
{
for(j = s[i-]-'a'+; j <= s[i]-'a'-; j++)
{
sum += c[-j][len--i];
}
} printf("%d\n",sum+);
} return ;
}

Code (组合数)的更多相关文章

  1. poj Code(组合数)

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9918   Accepted: 4749 Description ...

  2. Solution -「Code+#4」「洛谷 P4370」组合数问题 2

    \(\mathcal{Description}\)   Link.   给定 \(n,k\),求 \(0\le b\le a\le n\) 的 \(\binom{a}{b}\) 的前 \(k\) 大. ...

  3. P4370 [Code+#4]组合数问题2

    题目要求当\(0\leq a\leq b\leq n\)时,\(k\)个\(\tbinom{b}{a}\)的和的最大值 观察杨辉三角形,可以发现,最大的\(\tbinom{b}{a}\),为\(\tb ...

  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. LCM性质 + 组合数 - HDU 5407 CRB and Candies

    CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...

  7. C++单元测试 之 gtest -- 组合数计算.

    本文将介绍如何使用gtest进行单元测试. gtest是google单元测试框架.使用非常方便. 首先,下载gtest (有些google项目包含gtest,如 protobuf),复制目录即可使用. ...

  8. 【BZOJ-4591】超能粒子炮·改 数论 + 组合数 + Lucas定理

    4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 95  Solved: 33[Submit][Statu ...

  9. POJ 3904 Sky Code (容斥原理)

    B - Sky Code Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

随机推荐

  1. sql知识点的积累和使用过的例子

    越来越发现自己的sql方面的知识的欠缺,所以只能放低姿态一点一点的学了 一 游标和charIndex的使用. 游标我一直没用过,以前只是在同事们写的存储过程里见过,但是一直没看明白(可是我就是比较笨吧 ...

  2. kissy

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  3. oracle约束条件状态

    Oracle完整性约束有一下4种: • DISABLE NOVALIDATE • ENABLE NOVALIDATE • DISABLE VALIDATE • ENABLE VALIDATE   •  ...

  4. bootstrap 下的 validation插件

    http://reactiveraven.github.io/jqBootstrapValidation/

  5. Java反射学习(java reflect)(一)

    具有能够分析类能力的程序被称为反射,使用反射库可以编写能够动态操纵Java代码的程序. 一.开始 背景:Java运行时系统始终对所有对象维护一个被称为Runtime的类型标识,然后这货save着每个对 ...

  6. BFC块级格式化上下文简述

    做过页面编写的各位应该对定位不陌生了,这个样式表中的重头戏,也是最难把控的元素之一,今天在这里我们要讲到的就是与浮动与清除浮动相关的定位元素,对于定位有很多种,有绝对定位,还有相对定位,固定定位,静态 ...

  7. OC文件操作(2)

    NSFileManager 文件管理器完成文件的创建.移动.拷贝等管理操作 1.查询文件和目录  OC中查询路径下的目录主要分为浅度遍历和深度遍历.  浅度遍历  NSFileManager * ma ...

  8. 数据库,inner join,left join right join 的区别

    假设有两个表: 学生和课程 student:              class: id    student          id       class    studentId 1      ...

  9. jQuery常用技巧大放送

    1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...

  10. JDK与Tomcat的联系

    如果服务器没有安装JDK或没有配置JDK环境变量,则Tomcat启动出错 报错:需要JAVA_HOME 或JRE_HOME环境变量 所以必须首先安装JDK 配置环境变量 web服务器Tomcat才能运 ...