Code (组合数)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 7184 | Accepted: 3353 |
Description
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 word is maximum 10 letters length
• The English alphabet has 26 characters.
Output
Sample Input
bf
Sample Output
55 忽略了输出0的情况,wa了若干次。。。
#include<stdio.h>
#include<string.h>
int c[][]; void init()
{
memset(c,,sizeof(c));
for(int i = ; i <= ; i++)
{
c[i][] = ;
c[i][i] = ;
} for(int i = ; i <= ; i++)
{
for(int j = ; j < i; j++)
{
c[i][j] = c[i-][j-] + c[i-][j];
}
}
} int main()
{
init();
int i,j,sum;
char s[];
scanf("%s",s);
int len = strlen(s); int flag = ;
for(i = ; i < len; i++)
{
for(j = i+; j < len; j++)
{
if(s[i] >= s[j])
{
flag = ;
break;
}
}
if(flag == )
break;
}
if(flag == )
printf("0\n");
else
{
sum = ;
for(i = ; i <= len-; i++)
sum += c[][i]; for(j = ; j <= s[]-'a'-; j++)
sum += c[-j][len-]; for(i = ; i < len; i++)
{
for(j = s[i-]-'a'+; j <= s[i]-'a'-; j++)
{
sum += c[-j][len--i];
}
} printf("%d\n",sum+);
} return ;
}
Code (组合数)的更多相关文章
- poj Code(组合数)
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9918 Accepted: 4749 Description ...
- Solution -「Code+#4」「洛谷 P4370」组合数问题 2
\(\mathcal{Description}\) Link. 给定 \(n,k\),求 \(0\le b\le a\le n\) 的 \(\binom{a}{b}\) 的前 \(k\) 大. ...
- P4370 [Code+#4]组合数问题2
题目要求当\(0\leq a\leq b\leq n\)时,\(k\)个\(\tbinom{b}{a}\)的和的最大值 观察杨辉三角形,可以发现,最大的\(\tbinom{b}{a}\),为\(\tb ...
- POJ 1850 Code(组合数)
http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...
- POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数
http://poj.org/problem?id=3904 题意:给一些数,求在这些数中找出四个数互质的方案数. 莫比乌斯反演的式子有两种形式http://blog.csdn.net/out ...
- LCM性质 + 组合数 - HDU 5407 CRB and Candies
CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...
- C++单元测试 之 gtest -- 组合数计算.
本文将介绍如何使用gtest进行单元测试. gtest是google单元测试框架.使用非常方便. 首先,下载gtest (有些google项目包含gtest,如 protobuf),复制目录即可使用. ...
- 【BZOJ-4591】超能粒子炮·改 数论 + 组合数 + Lucas定理
4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 95 Solved: 33[Submit][Statu ...
- POJ 3904 Sky Code (容斥原理)
B - Sky Code Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- SQLite查询优化性能要点
Sqlite是轻量级的,在编译之后很小,其中一个原因就是在查询优化方面比较简单,它只是运用索引机制来进行优化的,经过对SQLite的查询优化的分析以及对源代码的研究,我将SQLite的查询优总结如下: ...
- 关于text-align无法居中的问题
昨天项目,一直出现一个无法居中的问题,最后发现竟然是text-align的问题,才发现自己对text-align的理解还是不够透彻,于是在此再举例分析下. css中的元素一共有三类:块元素.行内块和内 ...
- Android 5.0以上手机出现找不到so文件
问题描述 最近做项目出了一个bug项目中用到so文件,在5.0以上的手机上会报一个初始化异常错误,并提示找不到so文件.lib里目录结构类似如下 在Android5以下都没有问题,在5.0以上会报错 ...
- 文字排版--删除线(text-decoration:line-through)
如果想在网页上设置删除线怎么办,这个样式在电商网站上常会见到: 上图中的原价上的删除线使用下面代码就可以实现: .oldPrice{text-decoration:line-through;}
- Elasticsearch学习2--Elasticsearch数据类型简介
1.Elasticsearch 是 面向文档型数据库,这意味着它存储的是整个对象或者 文档,它不但会存储它们,还会为他们建立索引,这样你就可以搜索他们了.你可以在 Elasticsearch 中索引. ...
- Java操作hbase总结
用过以后,总得写个总结,不然,就忘喽. 一.寻找操作的jar包. java操作hbase,首先要考虑到使用hbase的jar包. 因为咱装的是CDH5,比较方便,使用SecureCRT工具,远程连接到 ...
- pthread_setcanceltype 线程取消
取消线程: (1)一个线程可以调用pthread_cancel来取消另一个线程. (2)被取消的线程需要被join来释放资源. (3)被取消的线程的返回值为PTHREAD_CANCELED ...
- 第17章课后题(高级Perl技巧)
17.1 写一个程序,从文件中读取一组字符串(每行一个),然后让用户键入模式以便进行字符串匹配. 对于每个模式,程序应该说明文件里共有多少字符串匹配成功,分别是哪些字符串. 对于所键入的每个新模式,不 ...
- Linux内存点滴:用户进程内存空间
原文出处:PerfGeeks 经常使用top命令了解进程信息,其中包括内存方面的信息.命令top帮助文档是这么解释各个字段的.VIRT , Virtual Image (kb)RES, Residen ...
- 熄灯问题 --POJ 2811-ACM
问题描述 盏灯的状态. 列的灯的状态就不改变. 请你写一个程序,确定需要按下哪些按钮,恰好使得所有的灯都熄灭.根据上面的规则,我们知道: 次按下时所产生的结果.因此,每个按钮最多只需要按下一次: (2 ...