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. AngularJS——grunt神器的安装

    前言: 刚开始学 angularJS,在慕课网上看的大漠老师的视频(http://www.imooc.com/learn/156),里面刚开始讲述了前端开发-调试-测试所使用的手段和工具,本人对前端开 ...

  2. [Windows 64] (搬运)价值¥ 6,499的软件Navicat Premium11.2.11 最新版及其注册机

    Navicat Premium可以连接6种数据库并开发> 转载于:http://www.52pojie.cn/thread-529020-1-1.html

  3. javaee添加验证码

    package com.zh.code; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import j ...

  4. iOS开发小技巧--设置按钮圆角

    方法一:代码设置 方法二:通过图形化界面

  5. Java-编写一个jdbc操作类

    1.通过读取文件配置 package 数据库操作类; /* * Db.java Created on 2007年8月20日, 上午 8:37 */ import java.io.*; import j ...

  6. c#创建ISS站点

    private void CreateWebSite() { try { string installPath = "C:\\Program Files\\MyWeb"; stri ...

  7. ORACLE在存储过程中记录日志的处理包

    Java开发过程中一般使用LOG4J来将程序的运行日志记录到文件中,在ORACLE存储过程中也需要记录日志,我将工作中自己整理的一个记录日志的包分享出来,其实很简单,希望大家多提意见. 一.表结构 为 ...

  8. sdibt 1244 烦人的幻灯片

    在这个OJ站还没号,暂时没提交,只是过了样例 真不愧是烦人的幻灯片,烦了我一小时 ---更新:OJ测试完毕,AC 烦人的幻灯片问题 Time Limit: 1 Sec  Memory Limit: 6 ...

  9. UDP 内网穿透 心跳

    参考:http://blog.csdn.net/jacman/article/details/ 1: 启动一个Server. 2: 启动两个Client. 然后从Server端的Console里边可以 ...

  10. unix/linux进程详解

    技术分享 启动新进程 stdlib.hintsystem(const char *string)whichequals to "sh -c string" 替换进程映像unistd ...