麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

組合數學 POJ 1850 Code

2019-11-14 12:36:55
字體:
來源:轉載
供稿:網友

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

題目大意 符合題意的字符串要滿足位于后面字母比前面大的條件,輸入一個字符串,若不滿足該條件,輸出0,否則輸出按照排序系統該字符串之前有多少個字符串。

解題思路 符合答案的字符串包括兩種: 1、字符串長度小于輸入字符串長度。標記輸入字符串的長度為length,假設字符串為 i (i < length),則滿足條件的值為c[26][i],可以理解為該情況為從26個字母中選取 i 個,從小到大依次排列。 2、字符串長度等于輸入字符串長度。從左至右依次檢索,對于每一位 i 而言,該位字符的取值范圍應至少比前一位字符大一且小于當前字符,即 ch=[str[i-1]+1,str[i]);又因為該位字符之后剩余字符的取值范圍為 ‘z’-ch,剩余字符長度為 length-i-1,即滿足條件的值為 c[‘z’-ch][length-i-1]。

代碼實現

#include <iostream>#include<cstdio>#include<cstring>using namespace std;int c[27][27];void init(){ for(int i=0; i<=26; 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]; } }}int main(){ char str[11]; int sum=0; scanf("%s%*c",str); init(); int length=strlen(str); for(int i=0; i<length-2; i++) { if(str[i]>str[i+1]) {
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产青草视频在线观看 | 黄色特级视频 | 91精品国产九九九久久久亚洲 | 成年性羞羞视频免费观看无限 | 日韩欧美电影在线观看 | 一级毛片手机在线观看 | 久久久电影电视剧免费看 | 免费观看一区 | 久久亚洲精品久久国产一区二区 | caoporn国产一区二区 | 久久精品视频一区二区三区 | 草久在线观看视频 | 黄色7777| 色综合网在线观看 | 毛片av网址 | 国产精品嘿咻嘿咻在线播放 | a视频在线播放 | 高潮娇喘嗯啊~文字 | 久久久青 | 黄污网站在线观看 | 99国产精成人午夜视频一区二区 | 性少妇freeseⅹbbwhd | 依人在线视频 | 国产精品影视 | 毛片在线免费观看视频 | 国产午夜精品一区二区三区在线观看 | 久久av免费 | 国产wwww| 成人毛片网 | 欧美成人精品一区 | 亚洲精品午夜国产va久久成人 | 日韩精品中文字幕一区二区三区 | 精品国产一级毛片 | 欧美精品电影一区 | 成人福利电影在线观看 | 91成人免费网站 | 国产91久久久 | 亚洲一区二区三区精品在线观看 | 国产激爽大片在线播放 | 国产精品久久久久网站 | 国产亚洲精品久久 |