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 ...
随机推荐
- 前端与编译原理——用JS写一个JS解释器
说起编译原理,印象往往只停留在本科时那些枯燥的课程和晦涩的概念.作为前端开发者,编译原理似乎离我们很远,对它的理解很可能仅仅局限于"抽象语法树(AST)".但这仅仅是个开头而已.编 ...
- 洛谷P1248 加工生产调度
流水作业调度问题 有\(N\)个作业要在两台机器\(M_1\)和\(M_2\)组成的流水线上完成加工.每个作业\(i\)都必须先花时间\(a_i\)在\(M_1\)上加工,然后花时间\(b_i\)在\ ...
- 会话技术之Session(购物车加入、查看和清空)
会话技术之Session session:服务器端会话技术 当我们第一次访问的服务器的时候,服务器获取id, 能获取id 要拿着这个id去服务器中查找有无此session 若查找到了:直接拿过来将数据 ...
- NOIP模拟 17.8.16
NOIP模拟17.8.16 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...
- Leetcode690.Employee Importance员工的重要性
给定一个保存员工信息的数据结构,它包含了员工唯一的id,重要度 和 直系下属的id. 比如,员工1是员工2的领导,员工2是员工3的领导.他们相应的重要度为15, 10, 5.那么员工1的数据结构是[1 ...
- C++中数字转换成字符串
头文件:<string> 转换函数:to_string(); 例如:int n=10; string str=to_string(n) ;
- [已转移]js事件流之事件冒泡的应用----事件委托
该文章已转移到博客:https://cynthia0329.github.io/ 什么是事件委托? 它还有一个名字叫事件代理. JavaScript高级程序设计上讲: 事件委托就是利用事件冒泡,只指定 ...
- CF789D Mike and distribution
题目连接 一道人类智慧题.... 这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值 我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一 ...
- 跟我一起认识axure(一)
第一步下载:https://www.axure.com.cn/ 第二步点击安装,一路next 第三步:认识Axure RP工作界面
- c++编译错误:invalid new-expression of abstract class type
原因: 出现这个错误原因是new 了一个抽象类出错,说明父类(接口)中有纯虚函数没有实现.接口里的纯虚函数全部需要实现,这样才能new 子类. 例如: 纯虚函数例如 ; 是纯虚函数,不是纯虚函数不作要 ...