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. ...
随机推荐
- 理解firewall
http://blog.csdn.net/dream361/article/details/54022470 //firewall介绍 http://www.jb51.net/article/103 ...
- VS2017 Pro未能找到路径“……\bin\roslyn\csc.exe”的解决方案
VS2017改用roslyn编译的,新的roslyn编译器,支持c# 6.0语法.它放到bin里面去是为了支持asp.net应用的动态编译. 它是通过nuget的包Microsoft.CodeDom. ...
- Dubbo -- 系统学习 笔记 -- 示例 -- 只订阅
Dubbo -- 系统学习 笔记 -- 目录 示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 只订阅 问题 为方便开发测试,经常会在线下共用一个所有服务可用的注册中心,这时,如 ...
- Spring-Mybatis --- 配置SqlSessionFactoryBean,整合Spring-Mybatis
要利用Mybatis首先是需要导入mybatis-x.x.x.jar,其次,要整合Spring和Mybatis需要导入mybatis-spring-x.x.x.jar. JAR : mybatis-x ...
- 使用HTML5监测网站性能
在这个信息爆炸的互联网时代,越来越多的人缺少了等待的耐心,网站性能对于一个网站来说越来越重要.以下为监控到的网站打开时间对跳出率的影响: 当网站打开时间在0-1秒时,跳出率为12% 当网站打开时间在1 ...
- pgpool-II 的使用
1.pgpool-II的概念 pgpool-II 是一个位于 PostgreSQL 服务器和 PostgreSQL 数据库客户端之间的中间件,它提供以下功能: 连接池 pgpool-II 保持已经连接 ...
- react中的hoc和修饰器@connect结合使用
在学习react-redux的时候,看到了修饰器这个新的属性,这个是es7的提案属性,很方便.于是我用@connect代替了connect(使用的时候需要配置,这里不赘述),省去了很多不必要的代码,但 ...
- 使用es6的蹦床函数解决递归造成的堆栈溢出
首先,我们先定义一个函数,使用递归的思想写求和的方法: function sum(x, y) { if (y > 0) { return sum(x + 1, y - 1); } else ...
- 【PHP】使用GD库实现 图像生成、缩放、logo水印和简单验证码
gd库是php最常用的图片处理库之一(另外一个是imagemagick),可以生成图片.验证码.水印.缩略图等等.要使用gd库首先需要开启gd库扩展, windows系统下需要在php.ini中将ex ...
- chrome插件开发,易懂