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 ...
随机推荐
- agc015D A or...or B Problem
题意:求用若干个(至少一个)[A,B]中的数进行or操作能得到多少本质不同的数 $1 \leq A \leq B < 2^{60}$ 一直在想数位dp,看了题解之后感觉自己就是个sb 我们先把$ ...
- Java 1.8 Stream 用例测试
package stream; import model.Student; import org.junit.jupiter.api.Test; import java.util.*; import ...
- vue移动端项目
用vue mint-ui jquery-weui写了一个移动端demo 技术栈 vue2.0 vue-router axios mint-ui jquery-weui webpack 页面截图 最后 ...
- Leetcode844.Backspace String Compare比较含退格的字符串
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = " ...
- The World's Top 15 Stock Exchanges by Domestic Market Capitalization
The World's Top 15 Stock Exchanges by Domestic Market Capitalization in 2008 4 Euronext Belgium, Fr ...
- 掀开SQL的神秘面纱,将优化进行到底
掀开SQL的神秘面纱,将优化进行到底 有这样一条奇怪的SQL,返回结果不足10行,逻辑读达到1.2w,存在索引却走多次全表扫描,如何揭开它神秘的面纱拯救系统性能,答案在这里,你不可错过! 本文来自上周 ...
- 两种RBAC权限控制模型详解
序言 由于最近一直卡在权限控制这个坎上,原来设计的比较简单的权限控制思路已经无法满足比较复杂一些的场景,因此一直在探索一种在大部分场景下比较通用的权限模型. 首先,这里说明一下两种RBAC权限模型分别 ...
- C++返回值优化
返回值优化(Return Value Optimization,简称RVO)是一种编译器优化机制:当函数需要返回一个对象的时候,如果自己创建一个临时对象用于返回,那么这个临时对象会消耗一个构造函数(C ...
- python isinstance和issubclass,区分方法和函数,反射
一.isinstance和issubclass 1.isinstance class Animal: def eat(self): print('刚睡醒吃点儿东西') class Cat(Animal ...
- java代码简单实现栈
1. 基于数组简单实现 /** * @author <a herf="mailto:yanwu0527@163.com">XuBaofeng</a> * @ ...