HDU 1708 简单dp问题 Fibonacci String
Fibonacci String
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4568 Accepted Submission(s): 1540
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 ?
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.
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.
ab bc 3
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
#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的更多相关文章
- 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 ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Max Sum (hdu 1003 简单DP水过)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- HDU - 1300 简单DP
题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买 坑点:排序会WA,喵喵喵? 为什么连续取就是dp的可行方案?我猜的.. ...
- [hdu 1398]简单dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...
- hdu 2845简单dp
/*递推公式dp[i]=MAX(dp[i-1],dp[i-2]+a[j])*/ #include<stdio.h> #include<string.h> #define N 2 ...
- hdu 1087 简单dp
思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<strin ...
- 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 ...
随机推荐
- android之网络操作(1)
一.网络操作 在网络操作中JAVA已经为我提供了一套API用来进行网络操作,在android开发中我们仍可以这套API来做开发.下面通过一个简单的例子来了解一下android下的网络操作. 点击图中下 ...
- AngularJS——grunt神器的安装
前言: 刚开始学 angularJS,在慕课网上看的大漠老师的视频(http://www.imooc.com/learn/156),里面刚开始讲述了前端开发-调试-测试所使用的手段和工具,本人对前端开 ...
- Office2010 pro附+激活工具
office2003经典的办公,office2010,很不错的办公工具配合Win7,就绝配! office2010,我也近几天接手她,慢慢熟悉... 00安装: 01激活: 内含office2010安 ...
- Linux使用
RedHat5 [cat] 将一个文件内容加入到另外一个另外一个文件中 参数 -n 或 --number 由 1 开始对所有输出的行数编号 -b 或 --number-nonblank 和 -n 相似 ...
- 【ZOJ 3844】Easy Task
题意 每次把序列中最大的数a的一个和最小的数b的一个变成a-b.求最后是否能使序列里的数全部相同,能则输出这个相同的数. 分析 一定是有解的,不断减少最大数的个数,最大数减少为0个时,就是减少了不同数 ...
- 畅所欲言第1期 - 从Viola&Jones的人脸检测说起
转载自http://c.blog.sina.com.cn/profile.php?blogid=ab0aa22c890006v0 不少人认识我或者听说我的名字都是因为我过去做的关于人脸检测的工作,那么 ...
- 【poj1009】 Edge Detection
http://poj.org/problem?id=1009 (题目链接) 不得不说,poj上的水题还是质量非常高的= =,竟然让本大爷写了一下午. 转自:http://blog.sina.com.c ...
- Uva11729 Commando War
相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可. sort大法好.印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到 /**/ #include< ...
- VirtualBox:Fatal:Could not read from Boot Medium! System Halted解决措施
打开VirtualBox加载XP虚拟机操作系统时,出现含有下面文字的错误: Could not read from Boot Medium! System Halted 或下面图中所示错误: ...
- mongo复习
$pop:-1移除数组的第一个元素,1移除最后一个元素eg: db.c.update({"name" : "toyota"},{$pop:{"titl ...