zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    你应该掌握的七种回归技术
    jar包运行
    Spark常见问题汇总,spark相关错误和解决方法,,,,,,,,,
    shell把字符串中的字母去掉,只保留数字
    excel求和结果不对
    Matlab实现PCA
    Spring3.0 AOP 具体解释
    POJ 1422 Air Raid(二分图匹配最小路径覆盖)
    TCP、UDP和HTTP
    2014世界互联网乌镇峰会 马云演讲实录
  • 原文地址:https://www.cnblogs.com/dealer/p/13044648.html
Copyright © 2011-2022 走看看