Code
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 8710   Accepted: 4141

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

题意是给了一个字符串,问其在给定字典中的位置,字符串本身要判断是否符合字典排序。

真的很讨厌做这种题目,感觉没什么分析,不会的话就怎么想都是不会了。但这个题目还算比较简单,找规律,要利用c[i][j]=c[i-1][j-1]+c[i-1][j];预处理出来比这个字符串长度少的所有数量,再从起始字符开始逐个找之前对应长度的字符串,数量都加起来就是答案。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int c[33][33],len,i,sum;
char temp[50]; void init()
{
int i,j;
memset(c,0,sizeof(c)); for(i=0;i<=32;i++)
{
for(j=0;j<=i;j++)
{
if(j==0||j==i)
c[i][j]=1;
else
c[i][j]=c[i-1][j-1]+c[i-1][j];
}
}
} bool pend(string temp)
{
for(i=1;i<len;i++)
{
if(temp[i]<temp[i-1])
return false;
}
return true;
} void dfs(int step)
{
if(step==len)
return; } int main()
{
while(scanf("%s",temp)!=EOF)
{
init();
sum=0;
len=strlen(temp); if(pend(temp))
{
for(i=1;i<len;i++)
{
sum+=c[26][i];
}
for(i=0;i<len;i++)
{
char temp_c;
if(i!=len-1)
{
if(i==0)
temp_c='a';
else
temp_c=temp[i-1]+1;
for(;temp_c<temp[i];temp_c++)
{
sum += c[26-(temp_c-'a'+1)][len-(i+1)];
}
}
else
{
if(len==1)
sum+=temp[i]-'a'+1;
else
sum += temp[i]-temp[i-1];
}
}
cout<<sum<<endl;
}
else
{
cout<<0<<endl;
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1850:Code 组合数学的更多相关文章

  1. poj 1850 code(组合数学)

    题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...

  2. poj:1850 Code(组合数学?数位dp!)

    题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][ ...

  3. POJ - 1850 Code(组合数学)

    https://vjudge.net/problem/POJ-1850 题意 输出某字符串在字典中的位置.字符串不合规则时输出0. 分析 首先判断字符串合法性,也就是判断是不是升序排列的.如果符合,以 ...

  4. POJ 1850 Code

    组合数学.... Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7202 Accepted: 3361 Descrip ...

  5. POJ 1850 Code(组合数)

    http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...

  6. POJ 1850 Code(找规律)

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7913   Accepted: 3709 Description ...

  7. POJ 1850 Code 字符串 难度:1

    题意: 1 如果是严格升序的字母字符串,那么可以输出非0解码,否则不能译码输出0 2 字符串解码 遵循递增原则,其值为 到现在为止的所有按字母序小于该字符串的数量 + 1; #include < ...

  8. 【POJ 1850】 Code

    [POJ 1850] Code 还是非常想说 数位dp真的非常方便! !. 数位dp真的非常方便!.! 数位dp真的非常方便! !! 重要的事说三遍 该题转换规则跟进制差点儿相同 到z时进一位 如az ...

  9. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  10. Code POJ - 1850 组合数学

    题意 :字符串从a=1 b=2 c=3....z=26  ab=27开始编号 每个都是升序的 给出字符串问是几号 思路:主要是要看n位字符串有多少个 这里需要用组合数学的思想  组合数用杨辉三角形递推 ...

随机推荐

  1. 索尼研发的新主机竟兼容现款PSVR!

    索尼PlayStation研发负责人Dominic Mallinson在接受媒体记者采访时表示,现款PSVR头戴式虚拟现实装置可用于下一代PS主机. 新主机兼容现款PSVR 而且,即便新主机上市也不要 ...

  2. Vue - 项目配置 ( element , 安装路由 , 创建路由 )

    1,安装element     :      vue add element 2,安装路由          :     vue add router 3,创建路由的过程  :   (1) 新建 vu ...

  3. 利用Jenkins实现jdk11+Maven构建springboot项目

    目录 原理图 前期准备 Jdk11安装 Jenkins安装 Maven安装 Jenkins的设置 插件安装 变量配置 搭建项目 1.通用配置 2.源码管理 3.构建触发 4.Maven的构建选项 5. ...

  4. lz-cms

    去年这个时候也是8月份,离开了生活9年的福州来到厦门,已整整一年的时间.离开福州的原因,就是不想让自己在安逸中沉沦下去,需要重新寻找技术的激情.来到新公司后,也开始投入老板梦想中的那个伟大CMS的研发 ...

  5. ActiveMQ消息队列和SignalR之日志实时监控及警报小实例

    主要技术: log4net-生成日志. ActiveMQ-生成日志的时候发送消息,并实时监控日志. SignalR-将ActiveMQ监控的日志实时显示到浏览器上,而不用刷新浏览器. 小实例介绍: 左 ...

  6. Flink on yarn以及实现jobManager 高可用(HA)

    on yarn https://ci.apache.org/projects/flink/flink-docs-release-1.8/ops/deployment/yarn_setup.html f ...

  7. 留学生如何把控好Essay写作结构

    留学生在国内写过作文,但是对于essay写作到底了解多少呢?大家觉得essay写作太难是语言问题,但是大家要明白,老师对于内容的考察远重于对语言的考察.同学们的essay写作如果能做到言之有理,自圆其 ...

  8. 实验吧-杂项-MD5之守株待兔(时间戳&python时间戳函数time.time())

    其实也有点蒙圈,因为从没做过和时间戳有关的题. 打开网站,将系统密钥解密得到一串值,而自己的密钥解密是空的,既然说是要和系统匹配,就把解密得到的值以get方式送出去. 但是发现还是在自己的密钥也发生了 ...

  9. Node.js NPM 作用

    章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json NPM ...

  10. POJ-3984 迷宫问题(BFS找最短路径并保存)

    问题: 定义一个二维数组:  int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...