POJ 1850 Code ,1496 Word Index(组合计数)
来源:互联网 发布:优化产业结构 编辑:程序博客网 时间:2024/05/05 19:34
转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526 by---cxlove
题目:字符串字母按字典序递增的为合法的,给出一个字符串问是第几个。
POJ 1496 http://poj.org/problem?id=1496
POJ 1850 http://poj.org/problem?id=1850
同样先求出字符串长度,那么长度小的部分容易求出。
对于要考虑字符串内要按升序怎么办呢,其实很简单,选出若干个不同的字母,这些字母的升序排列是唯一的。
那么对于长度为L的字符串,满足条件的个数便是从26个字母中选出L个,即C[26][L];
那么对于长度和原串长度一样的部分,同样是从高位往低位枚举。最高位的起点是'a',而之后的便要在前一位的基础上。
对于POJ 1850,给出的数据中可能出现不合法的,要判断后输出0
#include<iostream>#include<cstdio>#include<ctime>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<vector>#define C 240#define TIME 10#define inf 1<<25#define LL long longusing namespace std;int c[30][30]={0};void Init(){ for(int i=0;i<=26;i++){ c[i][0]=c[i][i]=1; for(int j=1;j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; }}char str[20];int main(){ Init(); while(scanf("%s",str)!=EOF){ int len=strlen(str),j; for(j=0;j<len-1;j++)if(str[j]>=str[j+1])break;if(j<len-1){printf("0\n");continue;} LL sum=0; for(int i=1;i<len;i++) sum+=c[26][i]; for(int i=0;i<len;i++){ char ch=i==0?'a':(str[i-1]+1); for(char j=ch;j<str[i];j++) sum+=c['z'-j][len-1-i]; } printf("%I64d\n",sum+1); } return 0;}
- POJ 1850 Code ,1496 Word Index(组合计数)
- Poj 1496 Word Index & Poj 1850 Code (计数 组合数)
- poj 1496 Word Index 计数/组合数学
- [ACM] poj 1496 Word Index(组合计数)
- POJ 1850 Code && 1496 Word Index 组合数学
- POJ 1850 Code/POJ 1496 Word Index(组合数学-字母串序号)
- POJ 1496 Word Index || POJ 1850 Code
- POJ 1850 Code POJ 1496 Word Index
- poj 1850 Code(组合计数)
- POJ 1496 Word Index 和POJ 1850 Code 动态规划
- poj 1850 Code(同 poj 1496 Word Index)
- 排列组合:poj 1496 Word Index+poj 1850 Code
- POJ 1496 Word Index组合数学(解题报告)
- POJ 1496 Word Index (组合数学 求字符串对应编码)
- POJ 1496 POJ 1850 组合计数
- POJ 1496 Word Index
- POJ 1496 Word Index
- POJ 题目1496 Word Index(排列组合)
- android TimerTask 的简单应用,以及java.lang.IllegalStateException: TimerTask is scheduled already错误的解决方法
- 数据库开发实例总结
- hdu1114,poj1384(完全背包)另附:http://acm.nyist.net/JudgeOnline/problem.php?pid=311
- android实现主动推送小结
- POJ 3009 Curling 2.0
- POJ 1850 Code ,1496 Word Index(组合计数)
- 在阶段总结中发现的问题
- i9250验机相关
- 成都旅游住宿购物交通攻略87
- 今天我又回到了这片土地,这里承载着我太多的回忆。572
- 在大连做安天技术论坛 CrackMe3
- DP入门--HDU1160
- QtSDK安装过程中usbdriver安装出错的解决方案
- poj 2299 Ultra-QuickSort(求逆序数,树状数组)