combinatorics dp math *1700

Please click on ads to support us..

C++ Code:

/*

懒猫点灯第一百一十三天



dp[i][0] = dp[i-1][1] + dp[i-2][1]

dp[i][1] = dp[i-1][0] + dp[i-2][0]



dp[i] = dp[i-1] + dp[i-2]

*/

#include<bits/stdc++.h>

using namespace std ;

#define ll long long

const ll N = 2e6+9 ;

const ll mod = 1e9+7 ;

const ll MAXN = 0x3f3f3f3f ;

ll Min( ll a , ll b ){ return a>b?b:a ; }

ll Max( ll a , ll b ){ return a>b?a:b ; }

ll Abs( ll x ){ return x>0 ? x : -x ; }

//gcd(a,b)=gcd(b,a)=gcd(-a,b)=gcd(|a|,|b|)=gcd(b,a mod b)

//ax+by = gcd(a, b) =d

ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

ll ksm( ll a , ll b ){

    ll res = 1 ;

    while( b > 0 ){

        if( b&1 ) res = res * a % mod ;

        b >>= 1 ;

        a = a*a % mod ;

    }

    return res ;

}

ll dp[ N ] ;

void solve(){

    ll n , m ; cin >> n >> m ;

   dp[ 1 ] = 2 ; dp[ 2 ] = 4 ;

   for( int i = 3 ; i <= Max(n,m) ; i ++ ){

        dp[i] = (dp[i-1] + dp[i-2])%mod ;

   }



   cout << ( dp[n] + dp[m] - 2 + mod )%mod << "\n" ;



   return ;

}

int main(){

    ios::sync_with_stdio(false) ; cin.tie(0) ;

    ll t = 1 ; //cin >> t ;

    while( t-- ) solve() ;

return 0 ;

}

/*

10 1

5 1 2 3 6 9 7 8 11 12

*/


Comments

Submit
0 Comments
More Questions

32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room