给定 n 和 r,接下来给定一个长度为 n 的序列 a。你需要对这个序列进行变换。
接下来 n 行第 i 行第一个数为 x ,该行接下来 x 个数 d_{i,j} 表示 a'_i=\sum\limits_{j=1}^xa_{d_{i,j}}。
同样的变换要重复 r 次,要求你输出变换后的序列,答案对 1000 取模(神奇的模数)。
多测,测 t 组。
## 正文
很难说这不是矩阵快速幂。
设变换矩阵为 $A$,本题的答案就是 $aA^r$。
其中变换矩阵 $A$ 表达为
$$
A_{i,j}=
\begin{cases}
0, &\exists\ k,d_{i,k}=j\\
1, &\text{otherwise}
\end{cases}
$$
直接做就好了,个人认为实际难度没有黑。
## 注意
由于 UVA 的神奇的特性,行末不要有多余的空格,会爆 PE,洛谷会 WA。
## code
~~小心多测怪~~
```cpp
#include <bits/stdc++.h>
#define fq(i,a,b) for (int i = (a); i <= (b); i++)
using namespace std;
inline int rd () {
int f = 1;
char ch = getchar ();
while (!isdigit (ch)) (ch == '-' ? (f = -1) : 0), ch = getchar ();
int num = 0;
while (isdigit (ch)) num = num * 10 + ch - '0', ch = getchar ();
return num * f;
}
#define d rd ()
const int maxn = 55;
const int p = 1000;
int A[maxn][maxn], B[maxn][maxn], C[maxn][maxn];
int n, r, a[maxn];
void mul () {
memset (C, 0, sizeof C);
fq (i, 1, n) fq (j, 1, n) fq (k, 1, n) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % p;
memcpy (B, C, sizeof B);
}
void mult () {
memset (C, 0, sizeof C);
fq (i, 1, n) fq (j, 1, n) fq (k, 1, n) C[i][j] = (C[i][j] + A[i][k] * A[k][j]) % p;
memcpy (A, C, sizeof A);
}
signed main () {
int t = d;
while (t--) {
n = d, r = d;
memset (A, 0, sizeof A);
memset (B, 0, sizeof B);
fq (i, 1, n) a[i] = d % p;
fq (i, 1, n) {int x = d; while (x--) A[i][d + 1] = 1;}
fq (i, 1, n) B[i][i] = 1;
while (r) {
if (r & 1) mul ();
mult ();
r >>= 1;
}
fq (i, 1, n) {
int ans = 0;
fq (j, 1, n) ans = (ans + a[j] * B[i][j]) % p;
cout << ans << " \n"[i == n];
}
}
return 0;
}
```