CF1239A. Ivan the Fool and the Probability Theory

Title: Ivan fool with probability theory

I thought it was a look at True probability theory ......

One topic is intended to:

There is a $ n \ times m $ trellis diagram, each compartment may be painted white or black, is now defined 'in FIG random': only up and down about the same at each point of a grid and its color, count the number of 10 ^ 7 + 9 $ $ modulo.

answer:

The first time I saw $ Fibonacci $ count.

First of all we think about the situation, dyed what?

A. Full board

As follows, as if nothing:

1

II. Cards together two blocks

If you find that there are two blocks of the same color, if you want to ensure that the entire legal certainly ranks colors painted the same.

2

2

This enables the two-dimensional chessboard divided the ranks of one-dimensional.

We now consider $ (1,1) $ painted white case (black empathy direct $ \ times 2 $ can)

Then the case of the first row has been determined (and can be pushed back over the column where the first row by)

Thus the number provided F_i $ $ $ i is placed above case $ columns situation.

Thus the initial state provided $ f_1 = 1, f_2 = 2 $

If the newly placed on a column and the same color, then the program number is $ f_ {i-2} $

If a color and on the contrary, the program number is $ f_ {i-1} $

那么$$f_i=f_{i-1}+f_{i-2}(i \geq 3)$$

That is $ Fibonacci $ persimmon ...... right ......

To seek the ranks were $ f $, but do not forget the case of a heavy (full board) lose.

then……

(Examination is recommended to play table to find the law)

 

#include <iostream>
#include <cstring>
#include <cstdio>
#define LL long long
#define N 111111

using namespace std;

const int Mod=1e9+7;

LL fib[N],m,n;

int main(){
	fib[1]=1,fib[2]=2;
	for(int i=3;i<=100000;i++){
		fib[i]=fib[i-1]+fib[i-2]%Mod;
	}
	cin>>n>>m;
	cout<<2*((fib[n]+fib[m])%Mod-1+Mod)%Mod<<endl;
}

Guess you like

Origin www.cnblogs.com/kalginamiemeng/p/CF1239A.html