社区讨论
0pts求(xuan)助(guan),马蜂良好
P10498石头游戏参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mm1q1kzq
- 此快照首次捕获于
- 2026/02/25 15:37 2 周前
- 此快照最后确认于
- 2026/02/25 15:37 2 周前
CPP
#include <bits/stdc++.h>
#define _(x, y) (x - 1) * m + y
using namespace std;
const int N = 70, M = 10;
struct Matrix {
int a[N][N];
} f1, f2[N], f3;
int n, m, T, act, ans;
char s[M][M], t[M][M];
inline Matrix operator * (const Matrix &c, const Matrix &d) {
Matrix e;
memset(e.a, 0, sizeof(e.a));
for (int j = 0; j <= n * m; j++)
for (int k = 0; k <= n * m; k++)
e.a[0][j] += c.a[0][k] * d.a[k][j];
return e;
}
inline void deal(int tim, int pos, char op) {
if (isdigit(op))
f2[tim].a[0][pos] = op ^ 48;
else if (op == 'D')
f2[tim].a[pos][pos] = 0;
else {
if (op == 'N') {
if (pos > m)
f2[tim].a[pos][pos - m] = 1;
f2[tim].a[pos][pos] = 0;
} else if (op == 'S') {
if (pos + m <= n * m)
f2[tim].a[pos][pos + m] = 1;
f2[tim].a[pos][pos] = 0;
} else if (op == 'E') {
if (pos % m != 0)
f2[tim].a[pos][pos + 1] = 1;
f2[tim].a[pos][pos] = 0;
} else {
if (pos % m != 1)
f2[tim].a[pos][pos - 1] = 1;
f2[tim].a[pos][pos] = 0;
}
}
}
inline void init() {
f1.a[0][0] = 1;
for (int i = 0; i <= n * m; i++)
f3.a[i][i] = 1;
for (int i = 1; i <= 60; i++) {
for (int j = 0; j <= n * m; j++)
f2[i].a[j][j] = 1;
for (int j = 1; j <= n; j++)
for (int k = 1; k <= m; k++) {
int pos = _(j, k);
int l = strlen(t[s[j][k] ^ 48] + 1);
char ac = t[s[j][k] ^ 48][i % l ? i % l : l];
deal(i, pos, ac);
}
f3 = f3 * f2[i];
}
}
inline void Pow(Matrix &c, Matrix &d, int tim) {
for (; tim; tim >>= 1) {
if (tim & 1)
c = c * d;
d = d * d;
}
}
int main() {
scanf("%d%d%d%d", &n, &m, &T, &act);
for (int i = 1; i <= n; i++)
scanf("%s", s[i] + 1);
for (int i = 0; i < act; i++)
scanf("%s", t[i] + 1);
init();
Pow(f1, f3, T / 60);
for (int i = 1; i <= T % 60; i++)
f1 = f1 * f2[i];
for (int i = 1; i <= n * m; i++)
ans = max(ans, f1.a[0][i]);
printf("%d\n", ans);
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...