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. 依赖注入(IOC) 详解

    https://blog.csdn.net/qq_27093465/article/details/52547290 https://blog.csdn.net/qq_27093465/article ...

  2. R Programming week1-Reading Data

    Reading Data There are a few principal functions reading data into R. read.table, read.csv, for read ...

  3. Farseer.net轻量级ORM开源框架 V1.3版本升级消息

    SHA-1: abca3b99801648fa23c7f4934de6c128f042cf47 * 提交新版本:V1.31.重构:FS.Mapping命名空间移到 FS.Core.Map中2.重构:对 ...

  4. 洛谷 P3388 【模板】割点

    题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...

  5. springMVC返回Base64位编码图片验证码

    import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;impor ...

  6. Codeforces_B.Maximum Sum of Digits

    http://codeforces.com/contest/1060/problem/B 题意:将n拆为a和b,让a+b=n且S(a)+S(b)最大,求最大的S(a)+S(b). 思路:考虑任意一个数 ...

  7. blockdev - 从命令行调用区块设备控制程序

    总览(SYNOPSIS) blockdev [options] commands devices 描述(DESCRIPTION) blockdev 工具允许从命令行调用区块设备控制程序. 选项(OPT ...

  8. 输入一个字符串输出ASCII的十六进制值

    #include <stdio.h> #include <string.h> #define LEN 1024 void main() { char s[LEN] = &quo ...

  9. xamarin.forms 绑定页面里指定元素的某个属性值

    {Binding Source={x:Reference elementName}, Path=BindingContext.propertyname, Mode=OneWay} elementNam ...

  10. E. Wrong Answer

    E. Wrong Answer time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...