C - Ivan the Fool and the Probability Theory---div2

Topic connection: https://codeforces.com/contest/1248/problem/C

Ideas:

Note that the relationship between the two rows up and down, if there are two row of squares in a row, then he must have two adjacent rows opposite him and above, if the current row no two consecutive squares adjacent to it two rows and it must be the same, and therefore, when the first row or the first column determining well, he also identified the following as well.

Therefore, we only need to consider when the law n == 1 ,, law to the line d [i] = d [i-1] + d [i-2]. From the first row next continuation is possible, so there will be d [x] + d [y] Yes, but will be more join the two groups, that is, two kinds of black and white, when a row over a rolling of statistics once, back to the column and the continuation of a statistical

Therefore, we must subtract multi statistic (2), the answer is (d [x] + d [y] -2)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1E5+7;
ll dp[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int x=max(n,m);
    dp[1]=2;
    dp[2]=4;
    for(int i=3;i<=x;i++) dp[i]=(dp[i-1]+dp[i-2])%mod;
    ll sum=(dp[n]+dp[m]-2+mod)%mod;
    cout<<sum<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Accepting/p/11716006.html