Fibonacci String

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4568    Accepted Submission(s): 1540

Problem Description
After little Jim learned Fibonacci Number in the class , 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 ?

 
Input
The first line contains a integer N which indicates the 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.
 
Output
For
each case,you should count how many times each 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.

 
Sample Input
1
ab bc 3
 
Sample Output
a:1
b:3
c:2
d:0
e:0
f:0
g:0
h:0
i:0
j:0
k:0
l:0
m:0
n:0
o:0
p:0
q:0
r:0
s:0
t:0
u:0
v:0
w:0
x:0
y:0
z:0
 
Author
linle
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1709 1710 1707 1714 1721 
 
 
 
其实也完全可以用模拟来解决,不过非常麻烦2
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int dp[][];
char str1[],str2[];
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(dp,,sizeof(dp));
memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
getchar();
int k;
scanf("%s %s %d",str1,str2,&k);
int len1=strlen(str1);
int len2=strlen(str2);
for(int i=;i<len1;i++)
dp[][str1[i]-'a']++;
for(int i=;i<len2;i++)
dp[][str2[i]-'a']++;
for(int i=;i<=k;i++){
for(int j=;j<;j++)
dp[i][j]=dp[i-][j]+dp[i-][j];
}
for(int i=;i<;i++)
printf("%c:%d\n",i+,dp[k][i]);
printf("\n"); }
return ;
}

HDU 1708 简单dp问题 Fibonacci String的更多相关文章

  1. hdu 2471 简单DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=(  dp[n-1][m],dp[n][m-1],d[i][k ...

  2. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. Max Sum (hdu 1003 简单DP水过)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. hdu 1257 && hdu 1789(简单DP或贪心)

    第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...

  5. HDU - 1300 简单DP

    题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买 坑点:排序会WA,喵喵喵? 为什么连续取就是dp的可行方案?我猜的.. ...

  6. [hdu 1398]简单dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...

  7. hdu 2845简单dp

    /*递推公式dp[i]=MAX(dp[i-1],dp[i-2]+a[j])*/ #include<stdio.h> #include<string.h> #define N 2 ...

  8. hdu 1087 简单dp

    思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<strin ...

  9. Tickets HDU - 1260 简单dp

    #include<iostream> using namespace std; const int N=1e5; int T,n; int a[N],b[N]; int dp[N]; in ...

随机推荐

  1. 10.C#匿名函数的变量捕获(五章5.5)

    首先感谢园友的指定,后续的文章一定会多码多想,出来的文章才有说服力.那今天接上篇我们来聊一聊匿名函数,对于匿名函数,我们知道使用delegate关键字,那我们来需要知道匿名函数在变量是的处理方式,先说 ...

  2. Beta版本的贡献率

    陈志灏:负责ACTIVITY部分的编写,与服务器间数据交换,贡献率百分比:%30 尤志明:负责服务器PHP编写,以及一些JAVA编程方面的编译问题的解决,贡献率百分比:%40 周子淇:负责layout ...

  3. 【BZOJ 3036】 绿豆蛙的归宿

    求期望的题目(~~~water~~~) 压了下代码,压成15行hhh: 我把代码压成这么丑估计也没有人看吧: 毕竟是zky讲的一个水题,就当给博客除草了:    dfs回溯时求当前节点的f,除以当前节 ...

  4. Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError

    SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackO ...

  5. 人工免疫算法-python实现

    AIAIndividual.py import numpy as np import ObjFunction class AIAIndividual: ''' individual of artifi ...

  6. PowerDesigner15下载、安装以及破解

    一.先安装PowerDesigner15(PowerDesigner15.1.0.2850),下载地址:点击下载 二.破解文件下载地址: 找到一个,居然这家伙的东西不是免费的:点击跳转 三.破解方法: ...

  7. 使用JMeter创建数据库(Mysql)测试

    我的环境:MySQL:mysql-essential-5.1.51-win32 jdbc驱动:我已经上传到csdn上一个:http://download.csdn.net/source/3451945 ...

  8. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

  9. Sql Server中启用分布式事务小结

    1.web服务器与数据库服务器同时启动msdtc服务 2. 2台服务器做出如下配置: 控制面板->管理工具->组件服务->计算机->我的电脑->本地DTC .Net示例: ...

  10. 高速公路(Highway,ACM/ICPC SEERC 2005,UVa1615)

    I think: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <m ...