Code

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

之前写了几道数位dp的题目 改成了字母的就又不会了

其实思路也很简单,就是分成小于长度的和等于长度的两种情况

小于长度的情况直接排列组合就可以了 等于长度的情况从高位枚举

http://blog.csdn.net/lyy289065406/article/details/6648492 看了这篇博文 感觉很好理解

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue> using namespace std; int c[30][30];
char str[12]; void Cmn()
{
c[0][0] = 1;
for(int i = 1; i < 30; i++){
c[i][0] = c[i][i] = 1;
for(int j = 1;j < i; j++){
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
} void solve()
{
int sum = 0;
for(int i = 1; i < strlen(str); i++){
sum += c[26][i];
} for(int i = 0; i < strlen(str); i++){
char ch = (!i)?'a':str[i - 1] + 1;
while(ch <= str[i] - 1){
sum += c['z' - ch][strlen(str) - i - 1];
ch++;
}
}
sum ++;
cout<<sum <<endl;
} int main()
{
Cmn();
cin>> str;
for(int i = 1; i < strlen(str); i++){
if(str[i] <= str[i - 1]){
cout<< 0<<endl;
return 0;
}
}
solve();
return 0;
}

poj1850Code的更多相关文章

  1. POJ1850-Code 递推数学

    题目链接:http://poj.org/problem?id=1850 题目大意: 按照字典序对升序排列组成的字母进行编号,给出一个长度不超过10的串,求出它的编号是多少?如果无法进行编号则输出0. ...

随机推荐

  1. ubuntu alsa2

    ALSA是Advanced Linux Sound Architecture简称.它包含一组kernel 驱动,一个应用编程接口(API)库以及一组工具函数.本文中,我们会向读者展示ALSA项目和组成 ...

  2. Java使用String类格式化当前日期

    在输出日期信息时,经常需要输出不同格式的日期格式,本实例中介绍了String字符串类中的日期格式化方法,实例使用不同的方式输出String类的日期格式参数值,组合这些值可以实现特殊格式的日期字符串. ...

  3. Java把数字格式化为货币字符串

    数字可以标志货币.百分比.积分和电话号码等,就货币而言,在不同的国家会以不同的格式来定义,本实例将接收用户输入的数字,然后在控制台中输出其货币格式,其中使用了不同国家的货币格式. 思路如下:使用Num ...

  4. 如何在windows上测试iphone?

    本教程将会让你没有mac照样测试iphone,这是我折腾了几天总结下来的,希望对大家有用. 先来几张效果图吧 方法很简单,但是配置起来说实话有点麻烦,先在电脑上安装vmware,在安装osx系统,在安 ...

  5. ios开发之--使用UILabel Category 计算UILabel内容大小

    在此仅做记录,代码如下:

  6. 【AI】Win10-Tensorflow

    一.安装 第一步:先安装anaconda3第二步:pip install --upgrade --ignore-installed tensorflow或者:pip install tensorflo ...

  7. 利用shell脚本自动获取awr报表

    观察Oracle数据库性能,oracle自带的awr功能为我们提供了一个近乎完美的解决方案,通过awr特性我们可以随时从数据库提取awr报告.通过报告可以了解一个系统的整个运行情况,生成的报告包括多个 ...

  8. PPT高手必须树立的十个理念

    08 2014年08月 [263职场技巧]PPT高手必须树立的十个理念 理念一:文字是用来瞟的,不是读的 我们时不时听到这样的言论:“PPT很简单,就是把Word里的文字复制.粘贴呗.”这其实是对PP ...

  9. RAC的搭建(一)--安装环境准备

    软硬件环境准备: 1.1 虚拟环境: VirtualBox上两个虚拟机,3G内存1核 1.2 软件环境: 数据库安装软件:p10404530_112030_LINUX_1of7.zip  p10404 ...

  10. mybatis 之 resultType="Map" parameterType="String"

    <select id="getAllGoodsForSouJiaYi" resultType="Map" parameterType="Stri ...