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. 提取DLL类库代码

    @SET destFolder=.\bin@XCOPY /I /Y %SYSTEMDRIVE%\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Pro ...

  2. Java基础知识强化之集合框架笔记18:List集合特有的ListIterator迭代器

    1. ListIterator(列表迭代器): ListIterator listIterator():List集合特有的迭代器 2. 代码示例: package cn.itcast_04; impo ...

  3. +load,+initialize原理

    +load,+initialize原理 1.load 父类的load方法在子类load方法之前调用,分类的load方法在原来类load方法之后调用,依赖类的load方法会在自己之前调用,总之所有的类的 ...

  4. String的hashCode原理

    参考下面这篇文章: http://blog.csdn.net/steveguoshao/article/details/12576849 http://blog.csdn.net/mingli1986 ...

  5. datagrid后台给每列添加js方法

    protected void dgExhList_ItemDataBound(object sender, DataGridItemEventArgs e) { string param = &quo ...

  6. 监听polygon变化

    Polygons are made of Paths which are just MVCArrays (in this case, they're a list of LatLng objects) ...

  7. Linux软件

    网上下载:Chrome Browser for Linux; sqlite;  WPS; symbol-fonts; 软件中心:Terminator; Code::Blocks IDE;  新立得软件 ...

  8. C++ STL的基本基本原理

    STL都是在内存的堆区分配的,但是其析构也是STL帮我们做好的,不用手动去delete. 1.vector 逻辑地址连续的一片内存空间,当空间不足,重新申请新的地址空间,将原有的数据复制过去,而新的地 ...

  9. topcoder算法练习2

    Problem Statement      In most states, gamblers can choose from a wide variety of different lottery ...

  10. 『重构--改善既有代码的设计』读书笔记----Extract Class

    在面向对象中,对于类这个概念我们应该有一个清晰的责任认识,就是每个类应该只有一个变化点,每个类的变化应该只受到单一的因素,即每个类应该只有一个明确的责任.当然了,说时容易做时难,很多人可能都会和我一样 ...