poj 1850 Code(组合计数)
来源:互联网 发布:淘宝卖家心酸 编辑:程序博客网 时间:2024/04/26 03:58
Problem Link
poj 1850 Code(组合计数)
分析
就是一个组合计数问题,只需要计数在当前字符串前面的字符串的个数,就行了,按照这个给定的序关系是很容易计数的.
AC code
#include <cstdio>#include <algorithm>#include <cstring>#include <string>#include <iostream>#include <vector>#include <queue>#include <map>#include <set>#include <bitset>#define INF 0x3f3f3f3f#define fi first#define se secondusing namespace std;typedef pair<int,int> Pair;typedef long long LL;const int maxn = 40+10;const int MOD = 1e6+7;LL C[maxn][maxn];string s;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]; }}bool ok(){ for(int i=0 ; i<s.size()-1 ; ++i) if(s[i]>s[i+1])return false; return true;}int main(){ init(); while (cin>>s) { LL sum = 0; if(ok()){ for(int i = 1 ; i<s.size() ; ++i){ sum +=C[26][i]; } int l = s.size(); for(int i = 0 ; i<s.size() ; ++i){ char tmp = 'a'; if(i>0)tmp =s[i-1]+1; if(i!=s.size()-1){ for( ; tmp<s[i] ; ++tmp){ sum+=C['z'-tmp][l-i-1]; } }else{ sum+=s[i]-tmp+1; } } } std::cout << sum << '\n'; } return 0;}
0 0
- poj 1850 Code(组合计数)
- Poj 1496 Word Index & Poj 1850 Code (计数 组合数)
- POJ 1850 Code ,1496 Word Index(组合计数)
- POJ1850:Code(组合计数)
- POJ 1496 POJ 1850 组合计数
- Code POJ 1850 组合数学
- poj 1850 Code 组合数学
- poj 1850 Code (组合数学)
- POJ 1850-Code(组合数学)
- POJ 1850:Code 组合数学
- POJ 1850 Code(组合数学)
- POJ-1850-Code-组合数学
- POJ-1850-Code-组合数学
- [poj 1850] Code 组合数学
- POJ 1850 Code (组合数学)
- 组合数学 POJ 1850 Code
- POJ 1850 code(组合数学)
- POJ - 1850 Code 组合数
- hduoj 2019数列有序
- Alluxio增强Spark和MapReduce存储能力
- pat-a1091. Acute Stroke (30)
- 获取Android设备唯一标识码
- UWP 入门笔记之学习资源
- poj 1850 Code(组合计数)
- 关于Ubuntu系统无法搜索到wifi信号的解决办法
- String为什么不可变
- thinkphp模板标签用法大全
- 夜间模式的实现
- Collection接口API
- 关于js中 alert(1&&2)的 输出(研究了半天,是懂非懂吧)
- 遍历集合
- 如何消除内存泄漏