• A. Ivan the Fool and the Probability Theory


    Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.

    To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of nn rows and mm columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.

    Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 109+7109+7.

    Input

    The only line contains two integers nn and mm (1n,m1000001≤n,m≤100000), the number of rows and the number of columns of the field.

    Output

    Print one integer, the number of random pictures modulo 109+7109+7.

    Example
    input
    Copy
    2 3
    
    output
    Copy
    8
    
    Note

    The picture below shows all possible random pictures of size 22 by 33.

     确定第一排的情况即可,递推推的有点懵逼

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #include <unordered_set>
    #include <unordered_map>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod =1e9+7;
    const int N = 100005;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    ll dp[N];
    ll n, m;
    int main()
    {
        cin >> n >> m;
        dp[1] = 2;
        dp[2] = 4;
        for (int i = 3; i < N; i++)
        {
            dp[i] = dp[i - 1] + dp[i - 2];
            dp[i] %= mod;
        }
        cout << (dp[n] + dp[m] - 2 + mod) % mod << endl;
        return 0;
    }
  • 相关阅读:
    栏目调用 sql语句
    一场豪赌 微软的未来取决于Windows 8
    mark
    [导入].net中的如何私有部署强命名组件
    q160问题,www.q160.com,ie被篡改
    解决jdgui保存源码自动添加注释的情况
    汉诺塔问题
    软件测试 方法总结
    javascript 基础篇4 window对象,DOM
    javascript 进阶篇1 正则表达式,cookie管理,userData
  • 原文地址:https://www.cnblogs.com/dealer/p/13044648.html
Copyright © 2020-2023  润新知