poj1850Code
Code
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 word is maximum 10 letters length
• The English alphabet has 26 characters.
Output
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的更多相关文章
- POJ1850-Code 递推数学
题目链接:http://poj.org/problem?id=1850 题目大意: 按照字典序对升序排列组成的字母进行编号,给出一个长度不超过10的串,求出它的编号是多少?如果无法进行编号则输出0. ...
随机推荐
- python使用tkinter写带界面的工具
python一般用来写纯脚本的居多,但也可以做有视图的产品出来,例如做网页和客户端工具.做成工具的好处是,让不懂代码的人也能使用,不需要去修改代码里面的参数,如果使用次数频繁,甚至比纯脚本跟节约时间: ...
- Missing iOS Distribution signing identity
打包上传appstore的时候报错如下: 解决方法: Download https://developer.apple.com/certificationauthority/AppleWWDRCA.c ...
- [AX2012]在SSRS报表中获取从Menuitem传入的记录
在较早版本的AX中我们运行一个报表时会用到类RunBaseReport,从它扩展一个子类,再由它运行报表,一个典型的Axapta3中的例子: class ReportProdInfo extends ...
- 架设SVN服务器
服务器端:windows 2003 + subversion 下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folder ...
- CentOS7图形界面启动报错unable to connect to X server
以前还可以正常启动图形界面,这次启动失败,报错unable to connect to X server 使用的是oracle用户,因为我是在oracle用户下创建的oracle数据库等 解决办法: ...
- C语言结构体和指针
指针也可以指向一个结构体,定义的形式一般为: struct 结构体名 *变量名; 下面是一个定义结构体指针的实例: struct stu{ char *name; //姓名 int num; //学号 ...
- N76E003之WDT(看门狗定时器)
N76E003提供一个看门狗定时器(WDT),它可以配置成一个超时复位定时器用于复位整个设备.一旦由于外界干扰设备进入非正常状态或挂起,看门狗可以复位恢复系统.这有用于监测系统运行以提高系统可靠性.对 ...
- odbc数据源for mysql
1. 下载mysql适配器并安装 mysql-connector-odbc-3.51.20-win32.exe 2. 配置数据源 “开始” ->”管理工具“ -> “数据源(ODBC)”- ...
- maven默认本地仓库目录
C:\Users\${姓名}\.m2\repository\
- Eclipse删除代码中所有注释及空格
替换方法: Ctrl+F 删除java注释: /\*{1,2}[\s\S]*?\*/ Ctrl+F 删除xml注释: <!-[\s\S]*?--> Ctrl+F 删除空白行: ^\ ...