poj 1850&&1496
来源:互联网 发布:淘宝虚假交易处罚 编辑:程序博客网 时间:2024/06/02 13:36
题意:用字符串的表示数,字符串符合字典序递增(这个条件就是为了出题而出,要不就太easy) 解法:组合数,借用网上的解法.
求组合数->递推关系式 C[i][j]=C[i-1][j-1]+C[i-1][j]
- /*************************************************************************
- > File Name: poj1496.cpp
- > Author: cy
- > Mail: 1002@qq.com
- > Created Time: 14/11/12 15:37:45
- ************************************************************************/
- #include<iostream>
- #include<cstring>
- #include <algorithm>
- #include<cstdlib>
- #include<vector>
- #include<cmath>
- #include<stdlib.h>
- #include<iomanip>
- #include<list>
- #include<deque>
- #include<map>
- #include <stdio.h>
- #include <queue>
- const int maxn=100+5;
- #define inf 0x3f3f3f3f
- #define INF 0x3FFFFFFFFFFFFFFFLL
- #define rep(i,n) for(i=0;i<n;i++)
- #define reP(i,n) for(i=1;i<=n;i++)
- #define ull unsigned long long
- #define ll long long
- #define cle(a) memset(a,0,sizeof(a))
- using namespace std;
- int C[maxn][maxn];
- void init()
- {
- int i,j;
- rep(i,27)
- {
- rep(j,i+1)
- {
- if(j==0||i==j)
- {
- C[i][j]=1;
- }
- else{
- C[i][j]=C[i-1][j-1]+C[i-1][j];
- }
- }
- }
- }
- char str[maxn];
- int len;
- bool getbool()
- {
- len=strlen(str);
- int i,j;
- rep(i,len){
- for(j=i+1;j<len;j++)
- {
- if(str[j]<=str[i])return false;
- }
- }
- return true;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- #endif
- /* ll sum=0;
- for(ll i=1;i<=1000000000000000LL;i+=2)
- {
- sum++;
- }
- cout<<sum<<endl;*/
- init();
- while(cin>>str)
- {
- int i,j,k;
- bool flag=getbool();
- if(!flag){
- cout<<0<<endl;
- continue;
- }
- int sum=0;
- for(i=1;i<len;i++)
- {
- sum+=C[26][i];
- }
- char temp;
- for(i=0;i<len;i++)
- {
- if(i==0){
- temp='a';
- }
- else{
- temp=str[i-1]+1;
- }
- while(temp<=str[i]-1)
- {
- sum+=C['z'-temp][len-i-1];
- temp++;
- }
- }
- cout<<sum+1<<endl;
- }
- return 0;
- }
0 0
- poj 1496 poj 1850
- poj 1850 poj 1496
- POJ 1496 Word Index || POJ 1850 Code
- POJ 1850 Code POJ 1496 Word Index
- POJ 1496 POJ 1850 组合计数
- poj 1496&1850
- POJ 1496 1850
- POJ 1496 1850
- poj 1850&&1496
- POJ 1496 + 1850 (数论-排列组合) (?)
- POJ 1850/ 1496 组合数学
- POJ 1496 Word Index 和POJ 1850 Code 动态规划
- POJ 1850 &&POJ 1496 Code 杨辉三角+组合数
- Poj 1496 Word Index & Poj 1850 Code (计数 组合数)
- poj 1850 Code(同 poj 1496 Word Index)
- 排列组合:poj 1496 Word Index+poj 1850 Code
- POJ 1496
- poj 1850
- CSipSimple结构浅析
- VB.net 类型转换问题
- ExtJs--09--javascript对象的方法的3种写法 prototype通过原型设置方法效率最好
- opencv Delaunay三角剖分例子
- java-javabean Introspector的应用
- poj 1850&&1496
- 可拖拽GridView代码解析
- 数据挖掘十大算法之C4.5
- sql语句2——表的创建、删除
- MATLAB字符转数据
- Android开发之常用开源库直接拿来用
- 微信电话本来了,虎口再夺食
- Android 颜色表
- ios 宽屏适配(iphone6及以上)