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. Java实现在线预览功能

    java实现在线预览功能,需要用到  jacob.dll jacob.jar   预览pdf所需js  pdfobject.min.js 将上传文件转为pdf保存. <div class=&qu ...

  2. 天马行空DevOps-Dev平台建设概述

    概述 DevOps(Development和Operations的组合词)是一组过程.方法与系统的统称,用于促进开发(应用程序/软件工程).技术运营和质量保障(QA)部门之间的沟通.协作与整合.它是一 ...

  3. ES6的新特性(17)——Generator 函数的异步应用

    Generator 函数的异步应用 异步编程对 JavaScript 语言太重要.Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可.本章主要介绍 Gener ...

  4. Vue工作原理小结

    本文能帮你做什么?1.了解vue的双向数据绑定原理以及核心代码模块2.缓解好奇心的同时了解如何实现双向绑定为了便于说明原理与实现,本文相关代码主要摘自vue源码, 并进行了简化改造,相对较简陋,并未考 ...

  5. 作业要求20181113-4 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 03

    作业要求:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2385 版本控制:[https://git.coding.net/lglr201 ...

  6. 第七次作业PSP

    psp 进度条 代码累积折线图 博文累积折线图 psp饼状图

  7. 关于虚拟机安装mac os 教程详解

    环境搭建 VMware下载 百度云盘下载:链接:http://pan.baidu.com/s/1pK8RcLl 密码:5jc5 Unlocker208 百度云盘下载:链接:http://pan.bai ...

  8. lintcode-129-重哈希

    129-重哈希 哈希表容量的大小在一开始是不确定的.如果哈希表存储的元素太多(如超过容量的十分之一),我们应该将哈希表容量扩大一倍,并将所有的哈希值重新安排.假设你有如下一哈希表: size=3, c ...

  9. ping(团队作业)

    一,团队成员 何守成 031602408(队长) 黄锦峰 031602411 肖逸清 031602435 张子纯 031602441 蔡志斌 031602602 柯叶祥 031602414 二.作业链 ...

  10. 【week12】psp

    psp 项目 内容 开始时间 结束时间 被打断 净时间 12月2日 写博客 对各小组评价 11:20 12:05 0 45 写博客 final评价1 23:40 23:57 0 17 12月5日 看论 ...