Code
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 9236   Accepted: 4405

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

大致题意:(与POJ1496基本一致)

输出某个str字符串在字典中的位置,由于字典是从a=1开始的,因此str的位置值就是 在str前面所有字符串的个数 +1

规定输入的字符串必须是升序排列。不降序列是非法字符串

不要求用循环输入去输入若干组字符串,但若输入非法字符串则输出0,且结束程序,这是和POJ1496最猥琐的区别,很多同学只注意到规定str的长度不同,以为把str数组长度改一下直接复制就能AC再多刷一题了,殊不知老是WA却找不到原因,大概就是这里出问题了.本题Str最长为10个字符

#include<cstdio>
#include<cstring>
using namespace std;
#define N 1010
char str[N];
int fac(int x){
int s=;
for(int i=;i<=x;i++){
s*=i;
}
return s;
}
int C(int n,int m){//如果用常规的 以前的很笨的方法,会造成大数的溢出
return fac(n)/fac(m)*fac(n-m);
}
int com(int n,int k){
if(k==) return ;
return com(n-,k-)*n/k;
}
int main(){
scanf("%s",str);
int len=strlen(str);
int sum=;
for(int i=;i<len-;i++){//把前面的都加起来,看看这个字符串len-1个长度的+len-2……1的字符串一共有多少个
sum+=com(,i+);
}
for(int i=;i<len;i++){
for(int j=i+;j<len;j++){
if(str[i]>str[j]){//如果字符串不是按照升序排列的,那么要输出0;
puts("");return ;
}
}
}
for(int i=;i<len;i++){//看看当前的字符串在“本长度”中排在什么样的位置。
for(int j=(i==?:str[i-]-'a'+);j<str[i]-'a';j++){//现在依然是在计算 与当前字符串一样长度的字符串的数量(之前的 ~ )
sum+=com(-j-,len-i-);//这个组合是固定开头的字符,选取后面的!
}//计算的过程是比如说第一个位置是k,开始固定'a'那么以后的len-1个位置上就是从b~z中选出组合,然后再固定b再选,……
}//直到第一个位置是k本身,第一个位置枚举完了,枚举地二个位置,从a开始直到第二个位置的字符本身,依次类推,直到最后一个字符枚举完毕;then本字符串之前的就计算完了,因为这样枚举都是本字符串之前的
printf("%d\n",sum+);
return ;
}

那就再刷一遍POJ1496

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1010
char str[N];
int fac(int x){
int s=;
for(int i=;i<=x;i++){
s*=i;
}
return s;
}
int C(int n,int m){
return fac(n)/fac(m)*fac(n-m);
}
int com(int n,int k){
if(k==) return ;
return com(n-,k-)*n/k;
}
int main(){
while(cin>>str){
int len=strlen(str);
int sum=,flag=;
for(int i=;i<len-;i++){
sum+=com(,i+);
}
for(int i=;i<len;i++){
for(int j=i+;j<len;j++){
if(str[i]>=str[j]){
puts("");flag=;i=len;break;
}
}
}
if(flag) continue;
for(int i=;i<len;i++){
for(int j=(i==?:str[i-]-'a'+);j<str[i]-'a';j++){
sum+=com(-j-,len-i-);
}
}
cout<<sum+<<endl;
}
return ;
}

POJ1850&&POJ1496的更多相关文章

  1. poj 算法 分类

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 最近AC题:2528   更新时间:2011.09.22  ...

  2. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  3. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  4. 北大ACM - POJ试题分类(转自EXP)

    北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...

  5. 北大ACM - POJ试题分类

    1.入门水题 可用于练手与增强自信 POJ-1003POJ-1004 POJ-1005 POJ-1207 POJ-3299 POJ-2159 POJ-1083POJ-3094 2.初级 2.1. 基本 ...

  6. poj1496 Word Index / poj1850 Code(组合数学)

    poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...

  7. POJ1850——Code(组合数学)

    Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...

  8. POJ1850 组合数学

    POJ1850 问题重述: 用26个小写字母进行编码,编码规则如下: 1)每个编码中前一个字母必须小于后一个字母 2)编码按照长度从小到大排列,相同长度按字典序进行排列 输入一个字母串,求解该编码对应 ...

  9. 数位dp poj1850

    题目链接:https://vjudge.net/problem/POJ-1850 这题我用的是数位dp,刚刚看了一下别人用排列组合,我脑子不行,想不出来. 在这题里面我把a看成1,其他的依次递增,如果 ...

随机推荐

  1. 深入理解brew link命令

    来源:https://newsn.net/say/brew-link-php71.html brew是mac机上面程序猿非常常用的软件包安装方式,其中有两组命令是需要大家知晓的.分别是: 第一组:br ...

  2. homebrew代理设置

    方法一 brew用curl下载,所以给curl挂上socks5的代理即可. 在~/.curlrc文件中输入代理地址即可. socks5 = "127.0.0.1:1080" 方法二 ...

  3. 15个最受欢迎的Python开源框架(转载)

    一.Django: Python Web应用开发框架 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C.它最初是被开发来用于管理 ...

  4. Asp.net问题集锦

    1.在Web应用开发中经常碰到这样的情况,Dropdownlist绑定的数据太多,用户要选择某一项必须从头找到尾,使用起来很不方便.最近我在工作中就碰到这种情况,公司内某个业务系统需要绑定几百条的厂家 ...

  5. 前端存储之indexedDB

    在前一个阶段的工作中,项目组要开发一个平台,为了做出更好的用户体验,实现快速.高质量的交互,从而更快得到用户的反馈,要求在前端把数据存储起来,之后我去研究了下现在比较流行的前端存储数据库,找到了ind ...

  6. ant安装配置

    点击进入ant官网,找到下载选项. 选择下载安装文件.其余的源文件和手册的下载步骤完全相同. 可以下载官网上对应系统的最新版本.也可以在old ant 版本中选择自己需要的版本.笔者需要ant-1.9 ...

  7. android项目 之 记事本(13) ----- 查看图片及播放录音

    本文是自己学习所做笔记,欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 今天就来实现下查看图片及录音的功能,在编辑或者浏览记事时,点击图片.打开一个自己 ...

  8. 解析Json数据

    一.json数据 [{"}] 二.关键代码 public class MainActivity extends Activity { @Override protected void onC ...

  9. Linux非阻塞IO(四)非阻塞IO中connect的实现

    我们为客户端的编写再做一些工作. 这次我们使用非阻塞IO实现connect函数. int connect(int sockfd, const struct sockaddr *addr, sockle ...

  10. acd - 1403 - Graph Game(博弈 + 二分图最大匹配)

    题意:N与P在玩游戏,N有 n1 个点,P有 n2 个点,N的点与P的点之间有 m 条无向边.将一个石子放在当中一点.N先移动石子.沿边移动一次,石子移动前的点及与该点相连的边被删除.接着到P移动石子 ...