https://vjudge.net/problem/POJ-1850

题意

输出某字符串在字典中的位置。字符串不合规则时输出0。

分析

首先判断字符串合法性,也就是判断是不是升序排列的。如果符合,以“vwxyz”为例,先计算长度小于5的串。

长度为1:C(26,1)

长度为2:由于规定了是升序序列,那么只要字母确定了,排列的情况也就确定了,于是此时可以认为方案数就等于从26个字母里任选两个出来,即C(26,2),经验证也是正确的。

长度为3:同上,C(26,3),长度为4:C(26,4)。

接下来是计算相同长度的,这里逐位来计算比较方便,例如从第0位开始(’v‘),计算aXXXX,bXXXX……uXXXX。然后第1位(‘w'),计算aXXX,bXXX……vXXX。以此类推,详细看代码就懂了。最后答案就是以上得到的总和+1。

预处理组合数用递推的方法。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set> #define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int N = 1e6+;
//const int MAXN = 210;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T;
void testcase(){
printf("Case #%d: ",++T);
}
const int MAXN = 3e5+;
const int MAXM = ;
int c[][];
void init(){
mset(c,);
for(int i=;i<;i++){
c[i][]=;
for(int j=;j<=i;j++){
c[i][j]=c[i-][j-]+c[i-][j];
}
}
}
char a[];
int main() {
#ifdef LOCAL
freopen("data.in","r",stdin);
#endif // LOCAL
init();
scanf("%s",a);
int len = strlen(a);
for(int i=;i<len;i++){
if(a[i-]>=a[i]){
puts("");
return ;
}
}
ll ans=;
for(int i=;i<len;i++) ans+=c[][i];
for(int i=;i<len;i++){
char ch = (!i)?'a':a[i-]+;
while(ch<=a[i]-){
ans+=c['z'-ch][len-i-];
ch++;
}
}
cout<<ans+;
return ;
}

POJ - 1850 Code(组合数学)的更多相关文章

  1. poj 1850 code(组合数学)

    题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...

  2. poj:1850 Code(组合数学?数位dp!)

    题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][ ...

  3. POJ 1850 Code

    组合数学.... Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7202 Accepted: 3361 Descrip ...

  4. POJ 1850 Code(组合数)

    http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...

  5. POJ 1850 Code(找规律)

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7913   Accepted: 3709 Description ...

  6. POJ 1850 Code 字符串 难度:1

    题意: 1 如果是严格升序的字母字符串,那么可以输出非0解码,否则不能译码输出0 2 字符串解码 遵循递增原则,其值为 到现在为止的所有按字母序小于该字符串的数量 + 1; #include < ...

  7. 【POJ 1850】 Code

    [POJ 1850] Code 还是非常想说 数位dp真的非常方便! !. 数位dp真的非常方便!.! 数位dp真的非常方便! !! 重要的事说三遍 该题转换规则跟进制差点儿相同 到z时进一位 如az ...

  8. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  9. Code POJ - 1850 组合数学

    题意 :字符串从a=1 b=2 c=3....z=26  ab=27开始编号 每个都是升序的 给出字符串问是几号 思路:主要是要看n位字符串有多少个 这里需要用组合数学的思想  组合数用杨辉三角形递推 ...

随机推荐

  1. PAT 1031 查验身份证

    https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 一个合法的身份证号码由17位地区.日期编号和 ...

  2. ModSecurity is an open source, cross-platform web application firewall (WAF) module.

    http://www.modsecurity.org/ ModSecurity is an open source, cross-platform web application firewall ( ...

  3. VC6到VC2010,项目迁移错误

    错误信息: error C2440: “static_cast”: cannot from “BOOL (__thiscall CSelectRect::* )(void)” to “BOOL (__ ...

  4. react + dva + ant架构后台管理系统(一)

    一.什么是dva dva是蚂蚁金服推出的一个单页应用框架,对 redux, react-router, redux-saga进行了上层封装,没有引入新的概念,但是极大的程度上提升了开发效率: 二.安装 ...

  5. [日常工作]GS使用安装盘修改密码后的处理

    1. GS服务器端有时候需要修改 9999 的用户密码.但是修改完密码之后有几个注意事项: 一般有两个可以修改注册的地方: 使用setup里面的修改用户密码 修改完密码之后要手工注册一下数据库实例 也 ...

  6. 小程序的wx.onAccelerometerChange

    https://www.2cto.com/kf/201802/724174.html(copy) 也许有人会问,小程序中都是竖直app形态,要横竖屏判断有什么用?即使判断出了横屏状态,你能把小程序横过 ...

  7. pandas 级联 concat append

    连接的一个有用的快捷方式是在Series和DataFrame实例的append方法.这些方法实际上早于concat()方法. 它们沿axis=0连接 #encoding:utf8 import pan ...

  8. rgb & rgba convert

    rgb & rgba convert RGB color to Hex, Pantone, RAL, HSL, HSV, HSB, JSON. Get color scheme. https: ...

  9. Omni(USDT)钱包安装(ubuntu)

    一.下载Omni Layer钱包 wget https://bintray.com/artifact/download/omni/OmniBinaries/omnicore-0.3.0-x86_64- ...

  10. BZOJ1036[ZJOI2008]树的统计——树链剖分+线段树

    题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u v ...