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 如果最后一个数字和前一个合并。。f(n-2)
不合并 f(n-1)
fn = fn-2 + fn-1
大数!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<fstream>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + ;
#define INF 0x3f3f3f3f
#define MAXN 203 int a[MAXN][MAXN];
char str[MAXN];
void add(int to[], int add[])
{
if (to[] < add[])
to[] = add[];
for (int i = ; i <= to[]; i++)
to[i] += add[i];
for (int i = ; i <= to[]; i++)
{
to[i + ] += to[i] / ;
to[i] %= ;
}
if (to[to[] + ] > )
to[]++;
}
void Init()
{
memset(a, , sizeof());
a[][] = , a[][] = ;
a[][] = , a[][] = ;
for (int i = ; i < MAXN; i++)
{
add(a[i], a[i - ]);
add(a[i], a[i - ]);
}
}
void print(int p)
{
for (int i = a[p][]; i > ; i--)
printf("%d", a[p][i]);
printf("\n");
}
int main()
{
int n, t;
scanf("%d", &n);
Init();
while (n--)
{
scanf("%s", &str);
t = strlen(str);
print(t);
}
}

1sting 大数 递推的更多相关文章

  1. HDU-1041-Computer Transformation,大数递推,水过~~

                                                                                  Computer Transformatio ...

  2. POJ 1737 Connected Graph (大数+递推)

    题目链接: http://poj.org/problem?id=1737 题意: 求 \(n\) 个点的无向简单(无重边无自环)连通图的个数.\((n<=50)\) 题解: 这题你甚至能OEIS ...

  3. HDU 1865 1sting (递推、大数)

    1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  4. UVa 10328 Coin Toss(Java大数+递推)

    https://vjudge.net/problem/UVA-10328 题意: 有H和T两个字符,现在要排成n位的字符串,求至少有k个字符连续的方案数. 思路:这道题目和ZOJ3747是差不多的,具 ...

  5. CodeVs 3150 (大数 + 递推)

    #include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...

  6. hdu 1133 Buy the Ticket (大数+递推)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

  8. Tiling(递推+大数)

    Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...

  9. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

随机推荐

  1. Win10 UWP开发:摄像头扫描二维码/一维码功能

    这个示例演示整合了Aran和微软的示例,无需修改即可运行. 支持识别,二维码/一维码,需要在包清单管理器勾选摄像头权限. 首先右键项目引用,打开Nuget包管理器搜索安装:ZXing.Net.Mobi ...

  2. Java 208道面试题及部分答案

    ---恢复内容开始--- 一.Java 基础 1.JDK 和 JRE 有什么区别? 答:JRE是java运行时环境,包含了java虚拟机,java基础类库.是使用java语言编写的程序运行所需要的软件 ...

  3. Angular jsonp 同源策略的问题

    引用:http://www.cnblogs.com/dengzy/p/5388357.html 说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决 ...

  4. 遮罩 HUD 指示器 蒙板 弹窗

    遮罩 HUD 指示器 蒙板 弹窗 UIAlertView的使用<代理方法处理按钮点击> UIAlertView *alertView = [[UIAlertView alloc] init ...

  5. mysql-oracle

    1.oracle数据崩导入时部分字段数据太长导入失败:原因是两边oracle字符集不一致 https://www.cnblogs.com/baoposhou/p/5669778.html 2.orac ...

  6. ssh设置免秘钥登录

    系统:CentOS7.2 需求:A服务器的fab用户需要使用www用户免秘钥登录到B服务器 换句话说,就是在A服务器的fab用户下,ssh    www@B服务ip   -p  端口  ,然后登录过去 ...

  7. VC++线程函数内怎么调用外部函数

    VC++线程函数内怎么调用外部函数 1.把外部函数做成静态函数,就可以直接调用了.2.把外部函数所在的对象通过线程函数参数传到线程里面来,这样线程里可以使用此对象及其函数了.

  8. 德尔福 XE5 安卓权限设置

    http://delphi.org/2013/10/delphi-xe5-android-uses-permissions/ The permissions required by a Delphi ...

  9. <Redis> 入门五 持久化RBD/AOF

    RDB RDB持久化是指在指定的时间间隔内将内存中的数据集快照写入磁盘(默认是 dump.rdb). 默认持久化机制,就是将内存中的数据以快照的方式写入二进制文件dump.rbd中. 触发快照的条件 ...

  10. 使用 PHP + shell 生成 一键设置权限的脚本。

    linux 系统 支持PHP脚本一键设置环境.shell脚本一键设置环境.那么 我今天 使用 PHP  + shell 生成 一键设置权限的脚本. 举例子:linux服务器 一键配置discuz网站环 ...