poj1850
来源:互联网 发布:协同过滤推荐算法 java 编辑:程序博客网 时间:2024/06/05 16:57
可以算组合吗?长度为2的字母,一共有C(26,2)个,这很难理解么?然后推一下当前要算的字母在哪个位置即可了。
#include <iostream>#include "string"using namespace std;int c[27][27];void combinations(){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 - 1] + c[i - 1][j];}}}return;}int main(){ combinations(); string s; while (cin>>s) {for(int i=1;i<s.length();i++) { if(s[i-1]>=s[i]){cout<<0<<endl;return 0;}}int sum=0; for(int i=1;i<s.length();i++)sum+=c[26][i]; for(int i=0;i<s.length();i++){char ch= (!i)?'a':s[i-1]+1; while(ch<=s[i]-1) {sum+=c['z'-ch][s.length()-1-i]; ch++;}}cout<<++sum<<endl; }}
0 0
- poj1850
- poj1850
- poj1850
- poj1850
- POJ1850
- poj1850
- poj1850
- Poj1850
- POJ1850-Code
- POJ1850&&POJ1496
- poj1850 Code
- poj1850 组合
- poj1850 Code
- poj1850 Code
- POJ1850:Code(组合计数)
- poj1850(组合数学)
- poj1850 Code 组合数学
- POJ1850-组合数学
- 2014寒假训练计划
- Qin Shi Huang's National Road System(次小生成树)
- poj-1042 && nyoj-30(Gone fishing)
- awk 计算两个数的百分比
- form中onsubmit的使用
- poj1850
- 利用httplib.HTTPSConnection 发送post请求的方式
- Windows Azure功能更新:网站服务支持过渡环境,支持异步任务,监控改进等
- Spark on Yarn:性能调优
- freebsd介绍
- wpa_supplicant软件架构分析
- 判断请求头中是否含有该属性来判断是否时ajax请求
- 黑马程序员_网络编程
- IT好博客