1sting
You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.
InputThe first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.
OutputThe output contain n lines, each line output the number of result you can get .
Sample Input
3
1
11
11111
Sample Output
1
2
8
自己找规律可得为Fibonacci数列,但递归到已为大位数运算,long long __int64皆不可以,最好的办法为开数组
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=;
int a[][maxn];
int main()
{
int n,i,j,count,T;
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
a[i][j]=;
}
}
a[][]=;
a[][]=;
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
a[i][j]=a[i][j]+a[i-][j]+a[i-][j];
if(a[i][j]>=)
{
a[i][j]=a[i][j]-;
a[i][j+]=a[i][j+]+;
}
}
}
cin>>T;
while(T--)
{
char b[];
cin>>b;
n=strlen(b);
for(i=;i>=;i--)
{
if(a[n][i]!=)
{
count=i;
break;
}
}
for(i=count;i>=;i--)
{
cout<<a[n][i];
}
cout<<endl;
}
return ;
}
1sting的更多相关文章
- hdu1865 1sting (递归+大数加法)
1sting Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 1865 1sting (递推、大数)
1sting Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDOJ/HDU 1865 1sting(斐波拉契+大数~)
Problem Description You will be given a string which only contains '1'; You can merge two adjacent ' ...
- D - 1sting(相当于斐波那契数列,用大数写)
Description You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ...
- 【hdoj_1865】1sting(递推+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...
- 1sting 大数 递推
You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or lea ...
- HDUOJ--1865 1string
1sting Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- Redis之Redis的数据类型
1.Redis的数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(无序集合)及ZSet(有序集合) 2.String(字符串) ...
随机推荐
- [置顶]
Netty学习总结(1)——Netty入门介绍
1.Netty是什么? Netty是一个基于JAVA NIO类库的异步通信框架,它的架构特点是:异步非阻塞.基于事件驱动.高性能.高可靠性和高可定制性. 2.使用Netty能够做什么? 开发异步.非阻 ...
- mysql关联更新表
UPDATE ecm_store s LEFT JOIN (SELECT store_id, COUNT(goods_id) AS goods_count FROM ecm_goods GROUP B ...
- iOS:UISplitViewController的创建
UISplitViewController是iPad特有的系统方法,主要效果就是呈现iPad的经典切割界面 代码创建实例: - (BOOL)application:(UIApplication *)a ...
- Linux Shell脚本编程学习笔记和实战
http://www.1987.name/141.html shell基础 终端打印.算术运算.经常使用变量 Linux下搜索指定文件夹下特定字符串并高亮显示匹配关键词 从键盘或文件里获取标准输入 [ ...
- APP-午饭去哪吃
走到这个快节奏的城市中.部门聚餐.朋友吃饭这些都是日常生活中时有发生的事情,往往吃的东西都是千篇一律,图的也仅仅剩下的是环境了.那么.非常纠结常常去的地方,怎么办呢?来吧.我们随机摇一个吧! wate ...
- IIC总线协议基础1
文档类别 文档标识 IIC总线协议基础1 当前版本号 V0.2 作 者 Louis 完毕时间 2015-05-27 IIC总线协议基础1 IIC总线协议基础1. 1. II ...
- 支持并发的httpclient(基于tcp连接池以及netty)
闲来无事,将曾经自己写的一个库放出来吧. . 有的时候会有这样子的需求: (1)serverA通过HTTP协议来訪问serverB (2)serverA可能会并发的像B发送非常多HTTP请求 类似于上 ...
- blog_html
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html> <html b:v ...
- NAS是什么
NAS是什么 简介 NAS(Network Attached Storage:网络附属存储)按字面简单说就是连接在网络上,具备资料存储功能的装置,因此也称为“网络存储器”.它是一种专用数据存储服务器. ...
- BZOJ 3600 替罪羊树+线段树
思路: 当然是抄的黄学长的题解啦 //By SiriusRen #include <cstdio> #include <algorithm> using namespace s ...