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. [转帖]从 2G 到 5G,手机上网话语权的三次改变

    从 2G 到 5G,手机上网话语权的三次改变 美国第一大电信运营商 Verizon 公司的 CEO Hans Vestberg 手持一部 iPad,屏幕上显示俯瞰地面的飞行地图.400 多公里外的洛杉 ...

  2. [linux学习]sysctl 以及 net.ipv4.ip_forward

    1. sysctl 命令显示 当前系统的参数配置信息 显示全部配置信息 sysctl -a 帮助信息主要如下: [root@k8s-master ~]# sysctl -help Usage: sys ...

  3. WPF将数据库和GridView绑定并更改GridView模板

    首先来看一下如何使用GridView,在前台的话代码如下:这里仅仅举出一个例子,GridView是作为子项嵌套在ListView中的,这里的数据源是通过绑定的方式来绑定到GridView中的. < ...

  4. 监控系统 & monitoring & DevOps

    监控系统 & monitoring & DevOps https://github.com/topics/monitoring https://github.com/marketpla ...

  5. Delphi编程中动态菜单要点归纳

      一.创建菜单并添加项目 在设计程序时,有时需要动态创建菜单, 通常使用以下的语句: PopupMenu1 := TPopupMenu.Create(Self);  Item := TMenuIte ...

  6. Delphi7/2007/2009/2010/XE/XE2/XE3/XE4/XE5/XE6/XE7/XE8/10最终版

    RAD Studio 10.1 Berlin(with Update1)http://altd.embarcadero.com/download/radstudio/10.1/delphicbuild ...

  7. python之tkinter使用-简单对话框

    # 简单对话框,包括字符.整数和浮点数 import tkinter as tk from tkinter import simpledialog def input_str(): r = simpl ...

  8. 在Python中调用C++模块

    一.一般调用流程 http://www.cnblogs.com/huangshujia/p/4394276.html 二.Python读取图像并传入C++函数,再从C++返回结果图像给Python h ...

  9. 学习笔记特别篇之orm的跨表

    models.Love.objects.filter(b__name="t1",g__nams="a1") 表示先inner join b on xx 再 in ...

  10. Android 访问 Webapi 更新UI

    首先,写一个访问webapi的工具类 import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import or ...