poj Code(组合数)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 9918 | Accepted: 4749 |
Description
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
Source
/*
组合数
题意是查一个字串的字典序排名
先求出长度比它小的,显然是ΣC 26 i(i<len)
然后求出长度等于它却比它小的。具体看代码。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 27 using namespace std;
int c[N][N],ans;
char str[N]; inline void combination()
{
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
if(!j || i==j)
c[i][j]=;
else
c[i][j]=c[i-][j-]+c[i-][j];
c[][]=;
return;
} int main()
{
combination();
while(cin>>str)
{
ans=;
int len=strlen(str);
for(int i=;i<len;i++)
if(str[i]<=str[i-])
{
cout<<""<<endl;
return ;
}
for(int i=;i<len;i++) ans+=c[][i];//长度小于它的所有方案
for(int i=;i<len;i++)
{
char ch=(!i)?'a':str[i-]+;//比上一个大
while(ch<str[i])//比当前这个小
{
ans+=c['z'-ch][len-i-];//长度等于它且排在它前面的所有方案
ch++;
}
}
cout<<++ans<<endl;
}
return ;
}
poj Code(组合数)的更多相关文章
- poj 3252 组合数
主要考察组合数知识,初始化的时候参考公式 首先先推个公式,就是长度为len的Round Numbers的个数. 长度为len,第一位肯定是1了. 那么后面剩下 len-1位 ...
- POJ Code the Tree 树的pufer编号
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2259 Accepted: 859 Desc ...
- Code (组合数)
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7184 Accepted: 3353 Description Trans ...
- POJ 1850 Code(组合数)
http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...
- POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数
http://poj.org/problem?id=3904 题意:给一些数,求在这些数中找出四个数互质的方案数. 莫比乌斯反演的式子有两种形式http://blog.csdn.net/out ...
- POJ 3904 Sky Code (容斥原理)
B - Sky Code Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 1942 Paths on a Grid(组合数)
http://poj.org/problem?id=1942 题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 . 思路 : ...
- [欧拉回路+手动开栈] poj 1780 Code
题目链接: http://poj.org/problem? id=1780 Code Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- POJ - 1850 B - Code
Transmitting and memorizing information is a task that requires different coding systems for the bes ...
随机推荐
- P1048 采药(洛谷,动态规划递推,01背包原题)
题目直接放链接 P1048 采药 这题只是01背包+背景故事而已 原题来的 PS:我写了一篇很详细的01背包说明,如果下面ac代码有看不懂的地方可以去看看 对01背包的分析与理解(图文) 下面上ac代 ...
- 洛谷——P2054 [AHOI2005]洗牌(扩展欧几里得,逆元)
P2054 [AHOI2005]洗牌 扩展欧拉定理求逆元 $1 2 3 4 5 6$$4 1 5 2 6 3$$2 4 6 1 3 5$$1 2 3 4 5 6$ 手推一下样例,你就会发现是有规律的: ...
- 「 HDU P2089 」 不要62
和 HDOJ 3555 一样啊,只不过需要多判断个 ‘4’ 我有写 3555 直接去看那篇吧 这里只放代码 #include <iostream> #include <cstring ...
- 深入理解PHP之strpos
概述 在php中经常用 strpos 判断字符串是否在另一个字符串中存在, 本文介绍 strpos 函数及其实现. strpos应用 <?php /* strpos示例 */ // test e ...
- Extract local angle of attack on wind turbine blades
Extract local angle of attack on wind turbine blades Table of Contents 1. Extract local angle of att ...
- TensorFlow — 相关 API
TensorFlow — 相关 API TensorFlow 相关函数理解 任务时间:时间未知 tf.truncated_normal truncated_normal( shape, mean=0. ...
- BZOJ 5106 [CodePlus2017]汀博尔
[题解] 二分答案.r要设好,不能随便设置为max(s,len),不然check的时候会爆long long #include<cstdio> #include<algorithm& ...
- ZOJ 3684 Destroy
Destroy Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- 【MangoDB分片】配置mongodb分片群集(sharding cluster)
配置mongodb分片群集(sharding cluster) Sharding cluster介绍 这是一种可以水平扩展的模式,在数据量很大时特给力,实际大规模应用一般会采用这种架构去构建monod ...
- 2.1 shuffle sort(洗牌)
1.目的:将数组以随机的顺序重新排序,类似洗牌的过程 2.用途用于快速排序或者任何以划分为基础的排序中,目的是减少最坏可能性发生的概率. 3.想法1:给数组的每一个元素产生一个随机的数字作为键,然后使 ...