Hihocode #1151: Domino cover Issue • Two

Source: Internet
Author: User

#1151: Domino cover issue • TwoTime Limit:10000mscase time Limit:1000msmemory LIMIT:256MB Description

Last week we studied the 2xN Domino problem, this week we might as well increase the difficulty, study the 3xN Domino problem?
So our question is: for the 3xN chessboard, how many different coverage methods are used to cover a 1x2 Domino?
First of all we can be sure that the odd length must not be covered, for even lengths, such as 2, 4, we have the following types of coverage:

Hint: 3xN Domino Overlay

input

Line 1th: an integer n. Represents the board length. 1≤n≤100,000,000

Output

Line 1th: An integer representing the number of coverage scenarios MOD 12357

Sample Input
62247088
Sample Output
4037


Solving problems: Making transfer equations
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 ConstLL mod =12357;5 structmatrix{6     intm[8][8];7 Matrix () {8 init ();9     }Ten     voidinit () { OneMemset (M,0,sizeofm); A     } -Matrixoperator*(ConstMatrix &RHS) { - Matrix ret; the          for(intK =0; K <8; ++k) -              for(inti =0; I <8; ++i) -                  for(intj =0; J <8; ++j) -RET.M[I][J] = (Ret.m[i][j] + m[i][k]*rhs.m[k][j])%MoD; +         returnret; -     } +     voidprint () { A          for(inti =0; I <8; ++i) { at              for(intj =0; J <8; ++j) -printf"%d", M[i][j]); -cout<<Endl; -         } -     } - }; in Matrix A, b; - voidQuickpow (LL index) { to      while(index) { +         if(index&1) A = A *b; -Index >>=1; theb = b*b; *     } $ }Panax Notoginseng BOOLtab[Ten][Ten]; - voidDfsintCurintSt) { the     if(cur >=3){ +         intSS =0; A          for(inti =2; I >=0; --i) { theSS <<=1; +SS |= tab[i][1]; -         } $b.m[st][ss]++; $         return; -     } -     if(!tab[cur][0]){ the         if(!tab[cur][1]){ -tab[cur][0] = tab[cur][1] =true;WuyiDFS (cur+1, ST); thetab[cur][0] = tab[cur][1] =false; -         } Wu         if(cur +1<3){ -             if(!tab[cur+1][0]){ Abouttab[cur+1][0] = tab[cur][0] =true; $DFS (cur+2, ST); -tab[cur+1][0] = tab[cur][0] =false; -             } -         } A}ElseDFS (cur +1, ST); + } the voidInitintSt) { -memset (tab,false,sizeoftab); $      for(inti =0, xst = st; I <3; ++i,xst >>=1) thetab[i][0] = xst&1; theDfs0, ST); the } the intMain () { -     intN; in      while(~SCANF ("%d",&N)) { the b.init (); the a.init (); About          for(inti =0; I <=7; ++i) init (i); thea.m[0][0] =1; the Quickpow (n); theprintf"%d\n", a.m[0][0]); +     } -     return 0; the}
View Code

Hihocode #1151: Domino Overlay problem • Two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.