zoukankan      html  css  js  c++  java
  • P2070

     

    Description

    有一个3*n的棋盘让你放入若干1*2的骨牌,要求将整棋盘恰好覆盖满。求方案数!

    Input

    一个整数n。

    Output

    方案数模12357的值。

    Sample Input

    2

    Sample Output

    3

    Hint

    1<=n<=100000000

    Source

    递推,矩阵快速幂

    这题先通过打表找出递推规律,然后推出转移矩阵,使用矩阵快速幂即可。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<iomanip>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<cstdio>
     7 #include<queue>
     8 #include<ctime>
     9 #include<cmath>
    10 #include<stack>
    11 #include<map>
    12 #include<set>
    13 #define rep(i,a,b) for(register int i=a;i<=b;i++)
    14 #define il inline
    15 #define ll long long
    16 using namespace std;
    17 const int N=2;
    18 int gi();
    19 int mod=12357,n;
    20 int a[N][N][N],s[N][N];
    21 void muti(int c,int d){
    22   rep(i,0,1)
    23     rep(j,0,1)
    24       rep(k,0,1)
    25         s[i][j]=(s[i][j]+a[c][i][k]*a[d][k][j])%mod;
    26   rep(i,0,1)
    27     rep(j,0,1)
    28     a[c][i][j]=s[i][j],s[i][j]=0;
    29 }
    30 int main() {
    31     freopen("HNOI.in","r ",stdin);
    32     freopen("HNOI.out","w",stdout);
    33     n=gi();
    34     if(n&1){puts("0");return 0;}
    35     n>>=1;
    36     a[0][0][0]=1,a[0][0][1]=3,a[1][0][1]=-1,a[1][1][0]=1,a[1][1][1]=4;
    37     
    38     while(n) {
    39       if(n&1) muti(0,1);
    40       muti(1,1);
    41       n>>=1;
    42     }
    43     cout<<a[0][0][0];
    44     return 0;
    45 }
    46 
    47 int gi() {
    48     int res=0,f=1;
    49     char ch=getchar();
    50     while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    51     if(ch=='-') ch=getchar(),f=-1;
    52     while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    53     return res*f;
    54 }
    View Code
  • 相关阅读:
    HDU 1850 Being a Good Boy in Spring Festival
    UESTC 1080 空心矩阵
    HDU 2491 Priest John's Busiest Day
    UVALive 6181
    ZOJ 2674 Strange Limit
    UVA 12532 Interval Product
    UESTC 1237 质因子分解
    UESTC 1014 Shot
    xe5 android listbox的 TMetropolisUIListBoxItem
    xe5 android tts(Text To Speech)
  • 原文地址:https://www.cnblogs.com/ypz999/p/6658612.html
Copyright © 2011-2022 走看看