POJ 1496 POJ 1850 组合计数
Code
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 8256 Accepted: 3906
Description
Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made
only of small characters of the English alphabet a,b,c, ..., z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).
The coding system works like this:
• The words are arranged in the increasing order of their length.
• The words with the same length are arranged in lexicographical order (the order from the dictionary).
• We codify these words by their numbering, starting with a, as follows:
a - 1
b - 2
...
z - 26
ab - 27
...
az - 51
bc - 52
...
vwxyz - 83681
...
Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.
Input
The only line contains a word. There are some constraints:
• The word is maximum 10 letters length
• The English alphabet has 26 characters.
Output
The output will contain the code of the given word, or 0 if the word can not be codified.
Sample Input
bf
Sample Output
55
Source
Romania OI 2002
/**************************************
author : Grant Yuan
time : 2014/10/12 17:06
algortihm: 组合计数
source : POJ 1496 POJ 1850
***************************************/ #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
char a[27];
int num[27][27];
long long ans;
bool check()
{
int l=strlen(a);
if(l==1) return 1;
for(int i=0;i<l-1;i++)
if(a[i]>=a[i+1]) return 1;
return 0;
}
void Get_num()
{
int l=strlen(a);
for(int i=0;i<=26;i++)
for(int j=0;j<=i;j++)
{
num[i][j]=0;
if(i==0||j==0) num[i][j]=1;
else num[i][j]=num[i-1][j]+num[i-1][j-1];
}
}
void Get_sum1()
{
int l=strlen(a);
ans=0;
for(int i=0;i<l;i++)
ans+=num[26][i];
}
void Get_sum2()
{
int l=strlen(a);
for(int i=0;i<l;i++)
{
char j;
if(i==0) j='a';
else j=a[i-1]+1;
for(;j<a[i];j++)
{
ans+=num['z'-j][l-i-1];
}
}
}
int main()
{
Get_num();
while(~scanf("%s",a)){
int l;
l=strlen(a);
if(l==1) {printf("%d\n",a[0]-'a'+1);continue;}
if(check()) {printf("0\n");continue;}
Get_sum1();
Get_sum2();
printf("%lld\n",ans);
}
return 0;
}
POJ 1496 POJ 1850 组合计数的更多相关文章
- POJ 2249-Binomial Showdown(排列组合计数)
Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18457 Accepted: 563 ...
- [总结]数论和组合计数类数学相关(定理&证明&板子)
0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...
- bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)
黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- 【BZOJ5491】[HNOI2019]多边形(模拟,组合计数)
[HNOI2019]多边形(模拟,组合计数) 题面 洛谷 题解 突然特别想骂人,本来我考场现切了的,结果WA了几个点,刚刚拿代码一看有个地方忘记取模了. 首先发现终止态一定是所有点都向\(n\)连边( ...
- 【BZOJ5323】[JXOI2018]游戏(组合计数,线性筛)
[BZOJ5323][JXOI2018]游戏(组合计数,线性筛) 题面 BZOJ 洛谷 题解 显然要考虑的位置只有那些在\([l,r]\)中不存在任意一个约数的数. 假设这样的数有\(x\)个,那么剩 ...
- 【BZOJ5305】[HAOI2018]苹果树(组合计数)
[BZOJ5305][HAOI2018]苹果树(组合计数) 题面 BZOJ 洛谷 题解 考虑对于每条边计算贡献.每条边的贡献是\(size*(n-size)\). 对于某个点\(u\),如果它有一棵大 ...
- 【BZOJ3142】[HNOI2013]数列(组合计数)
[BZOJ3142][HNOI2013]数列(组合计数) 题面 BZOJ 洛谷 题解 唯一考虑的就是把一段值给分配给\(k-1\)天,假设这\(k-1\)天分配好了,第\(i\)天是\(a_i\),假 ...
随机推荐
- iframe是否缓存页面探究
近期手里有个项目须要用iframe来调用每天都会变化的页面,后来想到iframe会不会缓存页面呢.于是写了个demo论证了下,结果例如以下: iframe的src假设是静态页面,就有可能会缓存.由于静 ...
- Android 四大组件学习之ContentProvider三
上节课学习怎样自己创建一个ContentProvider.以及用ContentResolver去操作ContentProvider. 今天我们用系统提供的ContentProvider. 先来个简单的 ...
- n个整数全排列的递归实现(C++)
全排列是很经常使用的一个小算法,以下是n个整数全排列的递归实现,使用的是C++ #include <iostream> using namespace std; int n = 0; vo ...
- 使用roslyn编译website项目
在Nuget中,添加Microsoft.CodeDom.Providers.DotNetCompilerPlatform. 在添加这个dll的时候,会自动在web.config中添加以下内容 < ...
- SAN (Storage Attached Network),即存储区域网络
NAS和SAN既竞争又合作,很多高端NAS的后端存储就是SAN.NAS和SAN的整合也是存储设备的发展趋势,比如EMC的新产品VNX系列. 关于NAS和SAN的区别,可以列出很多来.比如带宽大小,距离 ...
- checkbox复选框和div click事件重叠,点击div后复选框也被选中,同时改变div颜色,否则则不选中
checkbox复选框和div click事件重叠,点击div后复选框也被选中,同时改变div颜色,否则则不选中 <!DOCTYPE html> <html lang=" ...
- Xcode的一些控制台命令
命令 解释 break NUM 在指定的行上设置断点 bt 显示所有的调用栈帧,该命令可用来显示函数的调用顺序 clear 删除设置在特定源文件.特定行上的断点,其用法为:clear FILENAME ...
- Makefile经典教程(转)
转自:http://blog.csdn.net/ruglcc/article/details/7814546/ makefile很重要 什么是makefile?或许很多Winodws的程序员都不知道这 ...
- nginx令牌限制并发
http{ limit_req_zone $binary_remote_addr zone=req_one:10m rate=100r/s; server { listen 8080; server_ ...
- Java基础——选择排序、冒泡排序
1.选择排序 原理是直接从待排序数组里选择一个最小(或最大)的数字,每次都拿一个最小数字出来, 顺序放入新数组,直到全部拿完 代码演示: public class Test3 { public sta ...