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 ...
随机推荐
- 转:Android新特性介绍,ConstraintLayout完全解析
转:http://blog.csdn.net/guolin_blog/article/details/53122387 本篇文章的主题是ConstraintLayout.其实ConstraintLay ...
- jmeter 通过csv data set config 设置参数化后,执行结果显示为<EOF>
通过csv data set config 设置参数化后,执行结果显示为<EOF>: 反复确认相应的参数的设置均没有问题,其中csv文件编码方式采用uft-8.在csv data set ...
- C++ std::vector指定位置插入
使用vector,必须加上:#include <vector> 1.初始化vector,一般有这几种方式: std::vector<std::wstring> v1; //创建 ...
- Android——app基础
Android Application基础 系统启动过程 APK文件介绍 APK是Android Package的缩写,即android安装包.APK 文件其实是zip 格式,但后缀名被修改为apk ...
- vue中 表头 th 合并单元格,且表格列数不定的动态渲染方法
吐槽 今天,在vue中遇到 复杂表格的渲染 ,需要合并表头th的单元格,且合并单元格的那列的表头数据是动态数据,也就是不知道会有多少个表头列,而这几个表头列还分了好几个子表头. 这个需求在js里用Ju ...
- Python 运算符括号
- php封装的smarty类实例是怎样
* @link http://www.smarty.net/* @copyright 2008 New Digital Group, Inc.* @author Monte Ohrt <mont ...
- echarts radar 一些会用到了的功能记录
点击雷达图小标题进行相应操作 // options中添加,坐标轴的标签是否响应和触发鼠标事件,默认不响应. radar:{ triggerEvent: true } // 添加监听事件, 点击雷达图标 ...
- 仿Google Nexus菜单样式
在线演示 本地下载
- JS 寄生 继承
寄生构造函数 寄生构造函数的用途目的:给String内置对象功能扩充 稳妥的构造函数 继承 对象冒充继承 一般继承 组合继承 原型链继承:借助于中转函数和已有对象 寄生式继承:把原型式+工厂式结合而来 ...