# 1898: [Zjoi2005]swamp Swamp crocodile

Source: Internet
Author: User

Matrix multiplication.

The last scheme number can be obtained by matrix multiplication in adjacency matrix

Piranhas are periodic movements that can be represented by 12 matrices. 12 matrices are multiplied together to get a 13th matrix.

Then the K/12 part is transferred with the 13th matrix, and then the remaining matrix is multiplied.

#include <cstdio>#include<algorithm>#include<cstring>#defineLL Long Longusing namespacestd;Const intMAXN = -+Ten;Const intMoD =10000;intn,m,p1,p2,k,nf;intT[MAXN],Q[MAXN][MAXN];structMatrix {intA[MAXN][MAXN]; int*operator[] (intx) {returnA[x]; } Matrixoperator*(Matrix B) {matrix res;  for(intI=1; i<=n;i++)         for(intj=1; j<=n;j++)         for(intk=1; k<=n;k++) Res[i][k]= (Res[i][k]+a[i][j]*b[j][k])%MoD; returnRes; } Matrixoperator^ (inte) {Matrix res,tmp=* This;        Res.init ();  while(e) {if(e&1) res=res*tmp; TMP=tmp*tmp; E>>=1; }        returnRes; }        voidinit () {memset (A,0,sizeof(a));  for(intI=1; i<=n;i++) A[i][i]=1; } Matrix () {memset (A,0,sizeof(a)); }}a[ the],b,f;voidbuild () {scanf ("%d%d%d%d%d",&n,&m,&p1,&p2,&k); P1++; p2++;  for(intI=1, u,v;i<=m;i++) {scanf ("%d%d",&u,&v); U++; v++; B[U][V]=b[v][u]=1;                                                                                                                                                   } scanf ("%d",&NF);  for(intI=1; i<=nf;i++) {scanf ("%d",&T[i]);  for(intj=0; j<t[i];j++) {scanf ("%d",&Q[i][j]); Q[I][J]++; }    }         for(intI=1; i<= A; i++) {A[i]=b;  for(intj=1, v;j<=nf;j++) {v=q[j][i%T[j]];  for(intk=1; k<=n;k++) a[i][k][v]=0;    }} b.init ();  for(intI=1; i<= A; i++) b=b*A[i];     F.init (); F=f* (b^ (k/ A));  for(intI=1; I<= (k% A); i++) f=f*A[i]; printf ("%d\n", F[P1][P2]);}intMain () {build (); return 0; }

1898: [Zjoi2005]swamp Swamp crocodile

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.