Codeforces Round #594 (Div. 1A) lvan the Fool and Probability Theory

题意,一个只有黑白两色的矩阵

称概率图为满足每一个方格上下左右四个方向只有一个方格颜色和当前方格颜色相同的图

题解

打表

-0 2*1 2*2 2*3 2*5 2*8 2*13
-1 2*2 2*3 2*4 2*6 2*9 2*14
-2 2*3 2*4 2*5 2*7 2*10 2*15
-4 2*5 2*6 2*7 2*9 2*11  
-7 2*8 2*9 2*10 2*12 2*15  
-12 2*13 2*14 2*15 2*17    

发现每一行符合$f[i]=f[i-1]+f[i-2]-c$形式

$c$符合$abs(c[i])=abs(c[i-1])+abs(c[i-2])+1$形式

前两列也符合$f[i]=f[i-1]+f[i-2]-c$形式

递推

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define A 1111111
const ll mod=1e9+7;
ll n,m,c;
ll cha[A],thefirst[A],thesecond[A],ans[A];
int main(){
    scanf("%lld%lld",&n,&m);
    cha[1]=0;cha[2]=1;
    thefirst[1]=1;thefirst[2]=2;
    thesecond[1]=2;thesecond[2]=3;//最后统一
    for(ll i=3;i<=100000;i++)
        cha[i]=(cha[i-1]+cha[i-2]+1)%mod;
    for(ll i=3;i<=100000;i++)
        thefirst[i]=(thefirst[i-1]+thefirst[i-2])%mod;
    for(ll i=3;i<=100000;i++)
        thesecond[i]=(thesecond[i-1]+thesecond[i-2]-1)%mod;
    ans[1]=thefirst[n]%mod;ans[2]=thesecond[n]%mod;
    c=cha[n];
//  printf("1=%lld 2=%lld c=%lld\n",ans[1],ans[2],c);
    for(ll i=3;i<=100000;i++)
        ans[i]=(ans[i-1]+ans[i-2]-c)%mod;
    printf("%lld\n",ans[m]*2%mod);
}
View Code

猜你喜欢

转载自www.cnblogs.com/znsbc-13/p/11770493.html