Https://vijos.org/p/1049
Returns a sequence Containing N numbers. Then there are m replicas, K replicas for the initial sequence, and the final sequence.
Let's first look at a replacement, represent the replacement as a matrix, and then multiply the M replicas. Then, the initial sequence first executes this replacement K/m times, then sequentially executes the first K % m replacement, and then multiply the initial matrix.
Finally, pay attention to the order of Matrix Multiplication. A * B! = B *.
# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h> # include <algorithm> # define ll long # DEFINE _ ll _ int64 # define EPS 1e-12 # define PI ACOs (-1.0) # Define c 240 # define s 20 using namespace STD; const int maxn = 110; struct matrix {int mat [maxn] [maxn]; I NT n, m; void Init () {memset (MAT, 0, sizeof (MAT); For (INT I = 1; I <= 105; I ++) {mat [I] [I] = 1 ;}} M [11]; // represents each replacement. Int n, m; matrix MUL (matrix A, matrix B) {matrix ans; memset (ans. mat, 0, sizeof (ans. mat); ans. N =. n; ans. M = B. m; For (INT I = 1; I <=. n; I ++) {for (int K = 1; k <=. m; k ++) {if (. mat [I] [k] = 0) continue; For (Int J = 1; j <= B. m; j ++) ans. mat [I] [J] + =. mat [I] [k] * B. mat [k] [J] ;}} return ans;} matrix POW (matrix A, int N) {matrix ans; ans. N =. n; ans. M =. m; ans. init (); While (n) {If (N & 1) ans = Mul (ANS, a); A = MUL (a, a); N >=1;} return ans;} int main () {int num, K, Z; while (~ Scanf ("% d", & N, & M, & K) {matrix A, B;. init ();. M =. N = N; B. N = N; B. M = 1; for (INT I = 1; I <= N; I ++) B. mat [I] [1] = I; for (INT I = 1; I <= m; I ++) {memset (M [I]. mat, 0, sizeof (M [I]. mat); m [I]. M = m [I]. N = N; For (Int J = 1; j <= N; j ++) {scanf ("% d", & num); m [I]. mat [J] [num] = 1;} A = MUL (M [I], a); // note the order of multiplication} z = K/m; k = K % m; A = POW (A, Z); For (INT I = 1; I <= K; I ++) A = MUL (M [I], a); // note the order of multiplication A = MUL (a, B); For (INT I = 1; I <= N; I ++) {printf ("% d",. mat [I] [1]); if (I = N) printf ("\ n"); else printf ("") ;}} return 0 ;}