int trans[1 << 15][4], ch[256], g[maxm], h[maxm]; voidinit_trans(){ int M = (1 << m) - 1; for (int S = 0; S <= M; ++S) { for (int i = 1; i <= m; ++i) g[i] = g[i - 1] + (S >> i - 1 & 1); for (int k = 0; k < 4; ++k) { fill(h, h + maxm, 0); for (int i = 1; i <= m; ++i) { if (a[i] == k) h[i] = g[i - 1] + 1; else h[i] = max(h[i - 1], g[i]); } trans[S][k] = 0; for (int i = 1; i <= m; ++i) if (h[i] > h[i - 1]) trans[S][k] |= 1 << i - 1; } } }
int f[maxn][1 << 15], ans[maxm]; voidwork(){ cin >> s + 1 >> n; m = strlen(s + 1); for (int i = 1; i <= m; ++i) a[i] = ch[s[i]]; int M = (1 << m) - 1; init_trans(); fill(f[0], f[0] + maxn * (1 << 15), 0); f[0][0] = 1; for (int i = 0; i < n; ++i) for (int S = 0; S <= M; ++S) for (int k = 0; k < 4; ++k) f[i + 1][trans[S][k]] = (f[i + 1][trans[S][k]] + f[i][S]) % p; fill(ans, ans + maxm, 0); for (int S = 0; S <= M; ++S) ans[__builtin_popcount(S)] = (ans[__builtin_popcount(S)] + f[n][S]) % p; for (int i = 0; i <= m; ++i) cout << ans[i] << "\n"; }