POJ 3734 Blocks

Source: Internet
Author: User

Matrix Fast power.

Set AI to indicate that the red and green are even-numbered schemes after finishing the block

Set BI to show the number of programs with even numbers of red after I have finished painting

Set CI to indicate that the green is an even number of schemes after I have finished painting

Setting di means that after I have been finished, it is not even number of scenarios

Ai+1=ai+ai+bi+ci

Bi+1=ai+2*bi+di

Ci+1=ai+2*ci+di

Di+1=bi+ci+2*di

Then it is easy to construct the matrix.

#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;intN;Long LongMod=10007;structmatrix{Long Longa[5][5]; intR, C; Matrixoperator*(Matrix b);}; Matrix X, Y, Z; Matrix Matrix::operator*(Matrix B) {matrix C; memset (C.A,0,sizeof(C.A)); intI, j, K;  for(i =1; I <= R; i++)         for(j =1; J <= B.C; J + +)             for(k =1; K <= C; k++) C.a[i][j]= (C.a[i][j] + (a[i][k] * b.a[k][j])% MOD)%MOD; C.R= R; C.C =B.C; returnC;}voidinit () {n=n-1; memset (X.A,0,sizeofx.a); memset (Y.A,0,sizeofy.a); memset (Z.A,0,sizeofz.a); Y.R=4; Y.C =4;  for(inti =1; I <=4; i++) Y.a[i][i] =1; X.R=4; X.C =4; x.a[1][1]=2; x.a[1][2]=1; x.a[1][3]=1; x.a[1][4]=0; x.a[2][1]=1; x.a[2][2]=2; x.a[2][3]=0; x.a[2][4]=1; x.a[3][1]=1; x.a[3][2]=0; x.a[3][3]=2; x.a[3][4]=1; x.a[4][1]=0; x.a[4][2]=1; x.a[4][3]=1; x.a[4][4]=2; Z.R=1; Z.C =4; z.a[1][1]=2; z.a[1][2]=1; z.a[1][3]=1; z.a[1][4]=0;}voidRead () {scanf ("%d", &n);}voidWork () { while(n) {if(n%2==1) Y = y*y; N= N >>1; X= x*X; } Z= z*Y; printf ("%lld\n", z.a[1][1]);}intMain () {intCase=1; intT; scanf ("%d", &T);  while(t--) {read ();        Init ();    Work (); }    return 0;}

POJ 3734 Blocks

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.