zoukankan      html  css  js  c++  java
  • 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

    如果最后一个数字和前一个合并。。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 + 9;
    #define INF 0x3f3f3f3f
    #define MAXN 203
    
    int a[MAXN][MAXN];
    char str[MAXN];
    void add(int to[], int add[])
    {
        if (to[0] < add[0])
            to[0] = add[0];
        for (int i = 1; i <= to[0]; i++)
            to[i] += add[i];
        for (int i = 1; i <= to[0]; i++)
        {
            to[i + 1] += to[i] / 10;
            to[i] %= 10;
        }
        if (to[to[0] + 1] > 0)
            to[0]++;
    }
    void Init()
    {
        memset(a, 0, sizeof(0));
        a[1][0] = 1, a[1][1] = 1;
        a[2][0] = 1, a[2][1] = 2;
        for (int i = 3; i < MAXN; i++)
        {
            add(a[i], a[i - 1]);
            add(a[i], a[i - 2]);
        }
    }
    void print(int p)
    {
        for (int i = a[p][0]; i > 0; i--)
            printf("%d", a[p][i]);
        printf("
    ");
    }
    int main()
    {
        int n, t;
        scanf("%d", &n);
        Init();
        while (n--)
        {
            scanf("%s", &str);
            t = strlen(str);
            print(t);
        }
    }
  • 相关阅读:
    关于MYSQL 和INNODB的逻辑关系图。最好的理解是一点点动手做,观察,记录,思考。
    MYSQL的DOUBLE WRITE双写
    MYSQL 中binlog 参数的记录
    How to install pip
    gdb
    vim的基本使用
    012_fieldset.html
    010_header.html
    011_label.html
    008_img.html
  • 原文地址:https://www.cnblogs.com/joeylee97/p/7395557.html
Copyright © 2011-2022 走看看