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 ...
随机推荐
- Scala 中的函数式编程基础(三)
主要来自 Scala 语言发明人 Martin Odersky 教授的 Coursera 课程 <Functional Programming Principles in Scala>. ...
- android之外部文件存储和读取
这次借用上次读写内部存储的代码,只是对将更换文件的读写路径即可.这里需要对获取SDcard的读写权限. 一.AndroidManifest.xml 这里增加了对外部存储设备的读写权限 <?xml ...
- 使用Git进行代码管理心得
关于使用Git for Windows来clone和上传项目 首先到Git for Windows的官网下载并安装 在本地用来保存clone文件的文件夹右键,选择Git Bash Here: 在打开的 ...
- strncmp很好的函数
strcmp比较的是所有的长度,而strncmp可以比较前几个长度 strncmp(s1,s2,n);这样就比较了s1,s2,前n个长度的大小.
- MongoDB的安装及配置
MongoDB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐. Windows (1). 登录Mongodb官网点击下载 (2). 将zi ...
- Java编程思想学习(十三) java I/O
Java中使用流来处理程序的输入和输出操作,流是一个抽象的概念,封装了程序数据于输入输出设备交换的底层细节.JavaIO中又将流分为字节流和字符流,字节流主要用于处理诸如图像,音频视频等二进制格式数据 ...
- Notions of Flow Networks and Flows
这篇随笔是对算法导论(Introduction to Algorithms, 3rd. Ed.)第26章 Maximum Flow的摘录. ------------------------------ ...
- 初学Hibernate主键生成策略
具有业务含义的主键叫自然主键:随机生成,不具备业务含义的字段作为主键,叫代理主键. 在表与POJO类关系映射文件XXX.hbm.xml中,可通过配置id元素下generator节点的class属性指定 ...
- The mean shift clustering algorithm
The mean shift clustering algorithm MEAN SHIFT CLUSTERING Mean shift clustering is a general non-par ...
- Python socket编程之七:多窗口的应用
f1.py # -*- coding: utf-8 -*- import socket import struct import sqlalchemy import pandas ########## ...