Code
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 10059   Accepted: 4816

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

大致题意:问你一个字符串是按照某种顺序排列的第几个.
分析:先求出长度小于当前字符串的字符串有多少种,可以利用组合数快速统计,没有位上的限制,只是后一位要比前一位大.如果当前统计位数为len的,那么方案数就是C(26,len).
          再来统计长度等于当前字符串的字符串有多少种.因为整个序列是单调上升的,如果第i位我们固定的字符是第j个,那么剩下的len-i位就只能用26-j个字符了,那么方案数就是C(26-j,len-i).每个位置的字符的取值是有一个范围限制的.即它必须大于上一个字符,小于当前给定的字符.
犯的一个错误:我处理字符是把字符-‘a’变成数字来处理的,结果有一处忘了-'a'.最好的解决方法是不要-a,直接用一个int来存.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int c[][], len, ans;
char s[]; int main()
{
c[][] = ;
for (int i = ; i <= ; i++)
{
c[i][] = ;
for (int j = ; j <= ; j++)
c[i][j] = c[i - ][j - ] + c[i - ][j];
} while (~scanf("%s", s + ))
{
ans = ;
bool can = true;
len = strlen(s + );
for (int i = ; i <= len; i++)
if (s[i] <= s[i - ])
{
can = false;
break;
}
if (!can)
{
printf("0\n");
continue;
}
for (int i = ; i < len; i++)
ans += c[][i];
for (int i = ; i <= len; i++)
{
int ch = s[i] - 'a', ch2;
if (i == )
ch2 = ;
else
ch2 = s[i - ] - 'a' + ;
if (i == len)
ans += ch - ch2;
else
{
while (ch2 < ch)
{
ans += c[ - ch2 - ][len - i];
ch2++;
}
}
}
ans++;
printf("%d\n", ans);
} return ;
}

poj1850 Code的更多相关文章

  1. poj1496 Word Index / poj1850 Code(组合数学)

    poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...

  2. POJ1850——Code(组合数学)

    Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...

  3. poj1850 Code【组合数学】By cellur925

    题意: * 按照字典序的顺序从小写字母 a 开始按顺序给出序列 (序列中都为升序字符串)* a - 1* b - 2* ...* z - 26* ab - 27* ...* az - 51* bc - ...

  4. POJ1850 Code(组合+康托展开)

    题目问一个合法字符串的字典序是第几个,合法的字符串是指里面的字符严格递增. 先判断合不合法,然后用类似康托展开的过程去求.大概过程就是用组合数算出某长度某前缀有几个,累加起来. 真难一遍写对.. #i ...

  5. 【poj1850】 Code 数位dp+记忆化搜索

    题目大意:给你一个字符串,问你这个字符串的rank,如果这个字符串不合法,请直接输出0.(一个合法的字符串是对于∀i,有c[i]<c[i+1]) 字符串s的rank的计算方式:以字符串长度作为第 ...

  6. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  7. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  8. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

  9. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

随机推荐

  1. vim—多行注释、取消多行注释

    多行注释 命令模式: (1)将光标放在要注释的行首,按下组合键ctrl + v ,然后按上下键选取要注释的行. (2)按下大i键,然后插入要注释的符号 # (3)按ESC键,退出后,就会全部注释. 取 ...

  2. redis与mysql性能对比、redis缓存穿透、缓存雪崩

    写在开始 redis是一个基于内存hash结构的缓存型db.其优势在于速读写能力碾压mysql.由于其为基于内存的db所以存储数据量是受限的. redis性能 redis读写性能测试redis官网测试 ...

  3. “Hello World!”团队第七次Scrum立会

    "Hello world!"团队召开第七次Scrum立会.博客内容: 1.会议时间 2.会议成员 3.会议地点 4.会议内容 5.Todo list 6.会议照片 7.燃尽图 一. ...

  4. 每日Scrum--No.2

    Yesterday:找地图 Today: 找到最适合我们软件的地图版本 Problem:找不到特别匹配的版本

  5. Swift-自定义类的构造函数

    构造函数类似oc中的init方法默认情况下,创建一个,类会调用一个构造函数即使没写任何构造函数,编译器会默认一个构造函数如果是继承NSObject,可以对构造函数重写 class Person: NS ...

  6. 【final】140字互评②

    按照产品发布顺序 nice!----约吧 我们的团队展示相对于上次的手足无措,有了一定进步.但是整体还是不那么流畅总结起来的缺点是: 1.发布时,摄像头不清晰 且抖动 我们没有把摄像头固定,并且为了让 ...

  7. Hive查看执行日志

    HIVE-如何查看执行日志 HIVE既然是运行在hadoop上,最后又被翻译为MapReduce程序,通过yarn来执行.所以我们如果想解决HIVE中出现的错误,需要分成几个过程 HIVE自身翻译成为 ...

  8. [Oracle收费标准]

    http://www.oracle.com/us/corporate/pricing/technology-price-list-070617.pdf 1: 数据库 2. 中间件 3. weblogi ...

  9. mysql(六)索引的数据结构

    先做抽象定义如下: 定义一条数据记录为一个二元组[key, data],key为记录的键值,对于不同的数据记录,key是互不相同的:data为数据记录除key外的数据. B-tree的特点: d为大于 ...

  10. mybatis(一)MyBatis Generator

    在gradle中使用MyBatis Generator时,build.gradle配置如下: dependencies { mybatisGenerator group: 'org.mybatis.g ...