hdu 1708 Fibonacci String
Fibonacci String
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5012 Accepted Submission(s):
1693
, he was very interest in it.
Now he is thinking about a new thing --
Fibonacci String .
He defines : str[n] = str[n-1] + str[n-2] ( n > 1 )
He is so crazying that if someone gives him two strings str[0] and
str[1], he will calculate the str[2],str[3],str[4] , str[5]....
For
example :
If str[0] = "ab"; str[1] = "bc";
he will get the result ,
str[2]="abbc", str[3]="bcabbc" , str[4]="abbcbcabbc" …………;
As the string
is too long ,Jim can't write down all the strings in paper. So he just want to
know how many times each letter appears in Kth Fibonacci String . Can you help
him ?
number of test cases.
Then N cases follow.
In each case,there are two
strings str[0], str[1] and a integer K (0 <= K < 50) which are separated
by a blank.
The string in the input will only contains less than 30 low-case
letters.
letter appears in the Kth Fibonacci String and print out them in the format
"X:N".
If you still have some questions, look the sample output
carefully.
Please output a blank line after each test case.
To make
the problem easier, you can assume the result will in the range of int.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int f[][];
char s1[],s2[];
int i,j,T,n,m;
scanf("%d",&T);
while(T--)
{
scanf("%s %s %d",s1,s2,&n);
memset(f,,sizeof(f));
for(i=; s1[i]!='\0'; i++)
f[][s1[i]-'a']++; //字母转化为数字保存
for(i=; s2[i]!='\0'; i++)
f[][s2[i]-'a']++;
for(i=; i<=n; i++)
{
for(j=; j<; j++)
f[i][j]=f[i-][j]+f[i-][j]; //每一次都是前面两个相加
}
for(i=; i<; i++)
printf("%c:%d\n",i+'a',f[n][i]); //输出26个字母的个数
printf("\n");
}
return ;
}
hdu 1708 Fibonacci String的更多相关文章
- HDOJ(HDU) 1708 Fibonacci String
Problem Description After little Jim learned Fibonacci Number in the class , he was very interest in ...
- HDU 1708 简单dp问题 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Fibonacci String(hdu 1708)
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
- HDU 4054 Number String
HDU 4054 Number String 思路: 状态:dp[i][j]表示以j结尾i的排列 状态转移: 如果s[i - 1]是' I ',那么dp[i][j] = dp[i-1][j-1] + ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)
http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 1021 Fibonacci Again(找规律)
http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...
- HDU 4786 Fibonacci Tree(生成树,YY乱搞)
http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...
随机推荐
- scala的插值器
Scala 为我们提供了三种字符串插值的方式,分别是 s, f 和 raw.它们都是定义在 StringContext 中的方法. s 字符串插值器 val a = 2println(s"小 ...
- ES 6.X的环境搭建
一.ES windows环境下的安装 1.官网下载windows安装包 2.解压启动 F:\software\ES\elasticsearch-6.4.0\bin\elasticsearch 3.查看 ...
- webpack学习之—— Plugins
Plugins are the backbone of webpack! webpack 自身也是构建于你在 webpack 配置中用到的相同的插件系统之上! 插件目的在于解决 loader 无法实现 ...
- Python学习笔记(四)Python程序的控制结构
在学习了 Python 的基本数据类型后,我们就要开始接触Python程序的控制结构,了解 Python 是如何使用控制结构来更改程序的执行顺序以满足多样的功能需求.如果有的小伙伴在之前学过C语言,j ...
- python Match函数
- oracle-Dbca数据库模板
数据库模板是用xml文件格式保存在本地磁盘上的数据库配置的定义. Dbca能够使用两种类型的模板:种子模板和非种子模板. 种子模板指含有定义信息和实际的数据文件与重做日志文件的模板定义. 种子模板的优 ...
- linux类库之log4j-LogBack-slf4j-commons-logging
log4j http://commons.apache.org/proper/commons-logging/ http://logging.apache.org/log4j/2.x/ The Com ...
- 【JZOJ4898】【NOIP2016提高A组集训第17场11.16】人生的价值
题目描述 NiroBC终于找到了人生的意义,可是她已经老了,在新世界,没有人认识她,她孤独地在病榻上回顾着自己平凡的一生,老泪纵横.NiroBC多么渴望再多活一会儿啊! 突然一个戴着黑色方框眼镜,方脸 ...
- docker入门 基础命令 docker安装
docker入门 在学一门新知识的时候,超哥喜欢提问,why?what?how? wiki资料 什么是docker Docker 最初是 dotCloud 公司创始人 Solomon Hykes ...
- python 正则表达式匹配过程