Matrix Fast power.
Test instructions has actually told us that this is a matrix multiplication operation process.
Construct matrix: The bij of the XI column is labeled as 1.
For example, sample two:
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Long Long ConstMOD = +;intN, M;Long Longa[ -+5];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 () {memset (x.a,0,sizeofx.a); memset (Y.A,0,sizeofy.a); memset (Z.A,0,sizeofz.a); Y.R= N; Y.C =N; for(inti =1; I <= N; i++) Y.a[i][i] =1; X.R= N; X.C =N; for(intj =1; J <= N; J + +) { intXi scanf"%d", &XI); for(inti =1; I <= XI; i++) { intNum scanf"%d", &num); num++; X.A[NUM][J]=1; }} Z.R=1; Z.C =N; for(inti =1; I <= N; i++) z.a[1][i] =a[i];}voidRead () {scanf ("%d%d", &n, &m); for(inti =1; I <= N; i++) {scanf ("%lld", &A[i]); A[i]= A[i]%MOD; }}voidWork () { while(m) {if(M%2==1) Y = y*y; M= M >>1; X= x*X; } Z= z*Y; for(inti =1; I <= N; i++) {printf ("%lld", z.a[1][i]); if(i<n) printf (" "); Elseprintf"\ n"); }}intMain () {intT; scanf ("%d", &T); while(t--) {read (); Init (); Work (); } return 0;}
UVA 11551 experienced Endeavour