跳到正文

题解

题解:P11856 [CSP-J2022 山东] 吟诗

WorldMachine约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年2月25日
篇幅
约 2 分钟
获赞
10
题目
P11856

版本

  1. v1当前

怎么还搬 ARC 原题啊?泪目了。

直接做容易算重,考虑正难则反,求有多少个序列没有妙手。

X,Y,ZX,Y,Z 都非常小,考虑状压,fn,Sf_{n,S} 表示前 nn 个数,x∈Sx\in S 表示存在一个后缀和为 xx。

妙手代表的状态即为 {z,y+z,x+y+z}\{z,y+z,x+y+z\},不向包含这个状态的 SS 转移即可,复杂度为 O(nV2X+Y+Z)\mathcal O(nV2^{X+Y+Z})。

C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p = 998244353;
int n, m, x, y, z, e, ans = 1, f[41][1 << 17];
int main() {
	cin >> n >> x >> y >> z, m = (1 << (x + y + z)) - 1, e = (1 << (z - 1)) | (1 << (y + z - 1)) | (1 << (x + y + z - 1));
	f[0][0] = 1;
	for (int i = 1; i <= n; i++, ans = ans * 10ll % p) {
		for (int j = 0; j <= m; j++) {
			for (int k = 1; k <= 10; k++) {
				int s = ((j << k) | (1 << (k - 1))) & m;
				if ((s | e) != s) f[i][s] = (f[i][s] + f[i - 1][j]) % p;
			}
		}
	}
	for (int i = 0; i <= m; i++) ans = (ans + p - f[n][i]) % p;
	cout << ans << '\n';
}
原文