Code(组合数学)
Code
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 8766 Accepted: 4168
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
Source
Romania OI 2002
大神博客
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAX = 1e5+10;
int Bin[35];
int c[33][33];
char str[20];
char ch;
void ComBinnations()//打表,计算组合数
{
for(int i=0; i<=32; i++)
{
for(int j=0; j<=i; j++)
{
if(!j||i==j)
{
c[i][j]=1;
}
else
{
c[i][j]=c[i-1][j]+c[i-1][j-1];
}
}
}
c[0][0]=0;
}
int main()
{
int sum;
bool flag;
ComBinnations();
scanf("%s",str);
int len=strlen(str);
flag=false;
for(int i=1; i<len; i++)//判断是否是合法字符
{
if(str[i-1]>=str[i])
{
printf("0\n");
flag=true;
break;
}
}
if(!flag)
{
sum=0;
for(int i=1; i<len; i++)//计算比它小的字母排列
{
sum+=c[26][i];
}
for(int i=0; i<len; i++)//计算长度相等是字符的个数
{
ch=!i?'a':str[i-1]+1;
while(ch<str[i])
{
sum+=c['z'-ch][len-i-1];
ch++;
}
}
printf("%d\n",sum+1);//加上本身
}
return 0;
}
Code(组合数学)的更多相关文章
- POJ1850——Code(组合数学)
Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...
- poj:1850 Code(组合数学?数位dp!)
题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][ ...
- POJ 1850:Code 组合数学
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8710 Accepted: 4141 Description ...
- poj 1850 code(组合数学)
题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- Code POJ - 1850 组合数学
题意 :字符串从a=1 b=2 c=3....z=26 ab=27开始编号 每个都是升序的 给出字符串问是几号 思路:主要是要看n位字符串有多少个 这里需要用组合数学的思想 组合数用杨辉三角形递推 ...
- poj1496 Word Index / poj1850 Code(组合数学)
poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...
- poj1850 Code【组合数学】By cellur925
题意: * 按照字典序的顺序从小写字母 a 开始按顺序给出序列 (序列中都为升序字符串)* a - 1* b - 2* ...* z - 26* ab - 27* ...* az - 51* bc - ...
随机推荐
- 脚本:SQLServer 2008 生成某数据库中的所有索引创建脚本
--1. get all indexes from current db, place in temp table select schemaName = s.name, tablename = ob ...
- 实现 DIV 固定定位在网页主体部分最右侧
position:fixed 相对于窗口的固定定位,这个窗口可理解为可视窗口,除了浏览器自己的东西,剩下的就是这个可视窗口.而大部分的网页都是窄屏设计,比如说网页主体部分固定宽 1200px,或者自适 ...
- SC-控制Windows服务的命令
Windows自带一个控制服务的命令-SC,下面用Terminal Service做个简单例子: 查询Terminal Service的配置 C:\Users\jackie.chen>sc qc ...
- Lintcode: Maximum Subarray III
Given an array of integers and a number k, find k non-overlapping subarrays which have the largest s ...
- FileInputStream and FileOutputStream
Java FileOutputStream class Java FileOutputStream is an output stream for writing data to a file. If ...
- C++builder 图像字符流的存储和加载
__fastcall TForm6::TForm6(TComponent* Owner) : TForm(Owner) { #if 1 //for debug AllocConsole(); Atta ...
- 2-sat按照最小字典序输出可行解(hdu1814)
Peaceful Commission Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- JQuery权限管理
<title></title> <script src="JS/jquery-1.7.1.js"></script> <scr ...
- 20145207《Java程序设计》第三周学习总结
前言 24号回来的,书看的差不多了,博客一直没写,求老师原谅呀!!!!!哈哈哈哈.博客我从今天开始补,对着书,一天最多能弄个两篇毕竟写这个东西挺费心思德,当然我做事慢也有关系.但是我会尽快的.老实讲, ...
- C++之路起航——标准模板库(queue)
queue: FIFO队列:先进先出队列. 优先队列:对队列中的元素按优先级的大小输出. 定义: FIFO队列: queue<数据类性>变量名. 优先队列:priority_queue&l ...