poj 1850(以字符a开始长度为len的个数+数字本身)
来源:互联网 发布:大淘客到底是什么软件 编辑:程序博客网 时间:2024/06/05 14:36
Code
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 7265 Accepted: 3398
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.
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.
• 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
一道按位dp题目。
关键状态是 dp[i][j] 表示 以i开头长度为j的字符串个数。
初始化为dp[i][1] = 1;
转移方程为 dp[i][j] = dp[i-1][j+1] + dp[i-1][j + 2] + ... + dp[i-1][25];
再增加一个状态数组sum[i] 表示长度为i的满足条件的字符串有多少个,那么使用上面计算出来的dp可以很快求得。
那么以
vwxyz 为例:
首先result 先加上 sum[1] ~ sum[4]
然后对于长度为5的序列,需要一位一位讨论,这个和poj 3253按位计算的思路是一样的。
首先以小于v开头的长度为5的序列都满足要求。因此加上dp['a'][5] ~ dp['u'][5]
然后固定v,则以小于w大于v的序列也都满足要求。而这样的字母不存在。
然后固定前缀vw, 则以小于x大于w开头的序列也都满足要求。这个数字也是0.
以此类推,固定前缀vwx, vwxy, vwxyz求得的数字也都是0。。
最后再加上那个数字本身(再加一)
提交记录:
1、WA 因为没有看到题目中的要求,当字符串不合法时,输出0.
2、Accepted
- poj 1850(以字符a开始长度为len的个数+数字本身)
- jquery判断字符输入个数(数字英文长度记为1,中文记为2,超过长度自动截取)
- jquery判断字符输入个数(数字英文长度记为1,中文记为2,超过长度自动截取)
- n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字),当一个数字删除后,从被删除数字的下一个继续删除第m个数
- 【JS】JS判断字符输入个数(数字英文长度记为1,中文记为2,超过长度自动截取)
- SQL中汉字和字符的长度--len()函数
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。 提交
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
- jTextField的字符长度设为固定长度,超长不能输入 和 只能输入数字
- 字符转换为数字,以|分割
- n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字)。当一个数字删除后,从被删除数字的下一个继续删除第m个数字
- poj 3252(细心+组合数溢出+边界条件计算+算上数据本身)
- Stein算法求最大公约数
- 关于C++默认构造函数的定义和调用
- 【转】常见的正则表达式
- Ubuntu 12.04 安装Openfire
- poj 1850(以字符a开始长度为len的个数+数字本身)
- ACM竞赛
- AT&T 和Intel
- poj 1019(组外偏移->组内偏移)
- mac 如何显示隐藏文件和.点开头文件?
- 各种电子管
- poj 1942(裸组合数+隐式类型转换)
- 顺序表的基本操作(C++)
- ITAT模拟题