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. ...
随机推荐
- Javascript富文本编辑器
分享几款Javascript富文本编辑器 ueditor jqframework xheditor htmlbox kindeditor wymeditor jhtmlarea markitup ck ...
- 使用psutil库监控linux的系统资源和自定义进程的cpu 内存占用。
#coding=utf8 import time import psutil from pprint import pprint from logger_until import LoggerUnti ...
- 关于Android中Animation的停止【转载】
转载自:http://blog.csdn.net/easonx1990/article/details/8231520 最近遇到一个需求,通过在GridView上改变焦点,并且GridView上每个i ...
- Window系统、主函数和窗体函数这三者之间的关系
理解Window系统.主窗体.窗体函数这三者之间的关系,对于编写Windows程序十分重要. 主函数和窗体函数都是由Windows系统来调用的函数.仅仅只是主函数是程序启动之后.系统首先调用的函数: ...
- struts2 第一次使用 404 页面引发的一系列问题
环境:ubuntu . eclipse.struts-2.3.24 问题描写叙述: 1. struts2 訪问出现404 2. 严重: Exception starting filter Str ...
- Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id)等
对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOOL) isKindOfClass: classObj 判断是否是这个类或者这个类的子类的实例/ 判断是否是这个类 ...
- CWnd与HWND的区别与转换
CWnd与HWND的区别与转换 2011-10-20 10:29:30| 分类: VC学习库|字号 订阅 一.区别HWND是句柄,CWnd是MFC窗体类,CWnd中包含HWND句柄成员对象是 ...
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...
- codeforces水题100道 第四题 Codeforces Round #105 (Div. 2) A. Insomnia cure (math)
题目链接:http://www.codeforces.com/problemset/problem/148/A题意:求1到d中有多少个数能被k,l,m,n中的至少一个数整出.C++代码: #inclu ...
- Swift - 类型转换(as as! as?)
swift 类型转换 一,as 1,as使用场合 (1)从派生类转换为基类,向上转型(upcasts) class Animal {} class Cat: Animal {} let cat = C ...