Main topic
Give an no-show graph, there are some fish in this picture, their different time will appear in a fixed position, a periodic cycle, a person to walk on this chart, he can not and fish at a point. Ask from S to t walk K step how many kinds of scheme.
Ideas
Note that the fish cycle can only be 2/3/4, meaning that after a maximum of 12 time points, the state will be the same as at the beginning. So the preprocessing of 12 matrices is used to transfer. Divided into K/12 and k%12 to deal with.
When the fish is in a position, the current time from the position of the line and the previous time to reach the point of a column needs to be zeroed.
CODE
#define _crt_secure_no_warnings#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX#define MO 10000using namespace STD;intPointsstructmatrix{intNum[max][max];intW,h; Matrix (int_,int__): W (_), H (__) {memset(Num,0,sizeof(num)); } Matrix () {memset(Num,0,sizeof(num)); } Matrixoperator*(ConstMatrix &a)Const{Matrix Re (W,A.H); for(inti =1; I <= W; ++i) for(intj =1; J <= A.h; ++J) { for(intK =1; K <= H; ++K) re.num[i][j] + = num[i][k] * A.num[k][j]; RE.NUM[I][J]%= MO; }returnRe }voidClearhor (intLine) { for(inti =1; I <= points; ++i) Num[line][i] =0; }voidClearver (intLine) { for(inti =1; I <= points; ++i) Num[i][line] =0; }}src[ -];structfish{intcnt,num[Ten];voidRead () {scanf("%d", &cnt); for(inti =0; I < CNT; ++i)scanf("%d", &num[i]), ++num[i]; }}fish[max];intEdges,s,t;Long LongKintFishes Matrix Quickpower (Matrix A,Long LongY) {Matrix re (points,points); for(inti =1; I <= points; ++i) Re.num[i][i] =1; while(y) {if(y&1) Re = re * A; A = a * A; Y >>=1; }returnRe;}intMain () {Cin>> points >> edges >> s >> t >> K; ++s,++t; MatrixMap(points,points); for(intX,y,i =1; I <= edges; ++i) {scanf("%d%d", &x,&y); ++x,++y;Map. num[x][y] =Map. num[y][x] =1; } for(inti =0; I < A; ++i) Src[i] =Map;Cin>> fishes; for(inti =1; I <= fishes; ++i) Fish[i]. Read (); for(inti =0; I < A; ++i) { for(intj =1; J <= Fishes; ++J) {intpos = fish[j].num[i% fish[j].cnt];if(i) Src[i-1]. Clearver (POS); Src[i]. Clearhor (POS); }} Matrix base (points,points); for(inti =1; I <= points; ++i) Base.num[i][i] =1; for(inti =0; I < A; ++i) base = base * Src[i]; Matrix ans = quickpower (base,k/ A); K%= A; for(inti =0; I < K; ++i) ans = ans * src[i];cout<< Ans.num[s][t] << Endl;return 0;}
Bzoj 1898 Zjoi 2004 Swamp Swamp Alligator matrix multiplication