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 - ...
随机推荐
- CSS For Bar Graphs(maybe old)
Having a working knowledge of XHTML and CSS when developing applications is a big help in knowing wh ...
- Applescript 带参数调用某个App的方法
do shell script "open '/Users/eran/Documents/Workground/DragonAdventure/FlashCode/tools/SWFInfo ...
- 【Origin】 破阵子-未可留 征人调
几朝岁月,悠悠,容颜改,两鬓衰,可恨荣光不留! 一生事,忧心畔,可怜惶惶,不拿年岁当缠头: 只把扑朔往往,人生几回首: 等闲识得料峭处,一腔泪流: 曾记否,三十功名尘与土,不可解忧愁: 青春换得明日花 ...
- WebDriver 随笔
在webDriver中通过 driver.findElement进行定位元素时,往往是从页面的上到下依次寻找,根据该等位方式寻找到第一个元素. driver.findElement(By.id())有 ...
- javaIO整理
写在前面:本文章基本覆盖了java IO的全部内容,java新IO没有涉及,因为我想和这个分开,以突出那个的重要性,新IO哪一篇文章还没有开始写,估计很快就能和大家见面.照旧,文章依旧以例子为主,因为 ...
- ligerui+json_002_Grid用法、属性总结
原文更全面,地址: http://blog.csdn.net/dxnn520/article/details/8216560 // ================================== ...
- 三层与MVC
三层架构(3-tier architecture) 我们平时总是将三层架构与MVC混为一谈,殊不知它俩并不是一个概念.下面我来为大家揭晓我所知道的一些真相. 首先,它俩根本不是一个概念. 三层架构是一 ...
- json转化为java实体
import net.sf.json.JSONObject; Map<String, Object> classMap = new HashMap<String, Object> ...
- access调用联系
using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; us ...
- 【DP】斜率优化
斜率优化 入门题:PKU3709 很多人貌似都是做这道题来K斜率优化的,所以看了资料以后还是开始入手吧. 然而还是得跪求大神的程序啊 ORZ ORZ…… 其实理解斜率优化就是会列斜率不等式,还要理解剔 ...