首页 技术 正文
技术 2022年11月20日
0 收藏 654 点赞 2,998 浏览 2220 个字

Code

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

题目大意:

    判断一个字符串在字典中的位置。

    字符串必须保证为升序字符串才能合法。

解题思路:

    组合数学问题。

    首先通过dp打印出来com[][]杨辉三角形。

    假设字符串的长度为len。

    详情见备注。

Code:

 /*************************************************************************
> File Name: poj1850.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月28日 星期二 01时32分11秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
using namespace std;
long long com[][];
void init() /*打印杨辉三角*/
{
for (int i=; i<=; i++)
for (int j=; j<=i; j++)
if (!j||i==j)
com[i][j]=;
else
com[i][j]=com[i-][j-]+com[i-][j];
com[][]=;
}
int main()
{
init();
char num[];
scanf("%s",num);
int len=strlen(num),k;
for (k=;k<=len-;k++) /*判断是否为递增字符串*/
if (num[k]<=num[k-]) break;
if (k!=len)
{
cout<<<<endl;
return ;
}
long long ans=;
/*任意长度小于等于len的数都在其前面*/
for (int i=; i<=len-; i++)
ans+=com[][i];
/*计算最高位为[a,num[0])的个数*/
for (char i='a'; i<num[]; i++)
ans+=com['z'-i][len-];
/*计算前j位相同的个数*/
for (int j=;j<=len-;j++)
/*第j位可能的数字为[num[j-1]+1,num[j]) */
for (char i=num[j-]+;i<num[j];i++)
ans+=com['z'-i][len--j];
cout<<ans+<<endl;
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898