正文
增加 81 行删除 3 行
47 行未改动4849505152535455565758596047 行未改动然后宣布得出递推关系:$$S(x)=S(x-1)+S(x-d)$$因而对于位置 $L$,容易得出:$$dp_{m+2}=\sum_{i=2}^{m+1}S(L-p_i)dp_i$$对于 $0$ 到 $L$ 的方案数显然为 $S(L)$因此通过容斥得到答案为:$$S(L)+\sum_{i=2}^{m+1}(-1)^idp_i$$47 行未改动4849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713847 行未改动然后宣布得出递推关系:$$S(x)=S(x-1)+S(x-d)$$因而对于位置 $i$ 到位置 $L$ 距离为:$$S(L-p_i)dp_i$$对于 $0$ 到 $L$ 的方案数显然为 $S(L)$因此通过容斥得到答案为:$$S(L)+\sum_{i=2}^{m+1}S(L-p_i)dp_i$$代码:```cpp#include<bits/stdc++.h>#define cin_fast ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)#define fi first#define se second//#define int long long#define in(a) a = read()#define rep(i , a , b) for(int i = a ; i <= b ; i ++)using namespace std;typedef long long ll;const int N = 1e5 + 5 , mod = 998244353;const int inf = 0x3f3f3f3f;const long long INF = 0x3f3f3f3f3f3f3f3f;inline int read() {int x = 0;char ch = getchar();bool f = 0;while('9' < ch || ch < '0') f |= ch == '-' , ch = getchar();while('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + ch - '0' , ch = getchar();return f ? -x : x;}ll qpow(ll x , ll y) {ll ans = 1;for(; y ; x = (x * x) % mod , y >>= 1) if(y & 1) ans = (ans * x) % mod;return ans;}ll jc[20000005] , s[20000005];ll C(ll n , ll m) {if(n < m || n < 0 || m < 0) return 0;if(m == 0) return 1;return (jc[n] * qpow((jc[m] * jc[n - m]) % mod , mod - 2)) % mod;}struct node{int t , p;}a[N];ll dp[N];bool cmp(node x , node y) {if(x.p == y.p) return x.t < y.t;return x.p < y.p;}signed main() {//cin_fast;ll L , d , m;in(L) , in(d) , in(m);for(int i = 1 ; i <= m ; i ++) in(a[i].t) , in(a[i].p);jc[0] = 1;for(int i = 1 ; i <= L + L ; i ++) jc[i] = (jc[i - 1] * i) % mod;s[d] = 1;for(int i = d + 1 ; i <= L + L ; i ++) s[i] = (s[i - 1] + s[i - d]) % mod;a[++ m] = {0 , 0};sort(a + 1 , a + m + 1 , cmp);dp[1] = 1;for(int i = 2 ; i <= m ; i ++) {int x2 = a[i].t , y2 = a[i].p;for(int j = 1 ; j < i ; j ++) {int x1 = a[j].t , y1 = a[j].p;ll k = x2 - x1 , n = y2 - y1;if(k <= 0 || n < k * d) continue;n -= k * d;ll w = C(n + k - 1 , k - 1);dp[i] += (w * dp[j]) % mod;dp[i] %= mod;}dp[i] = mod - dp[i];}ll ans = s[L];for(int i = 2 ; i <= m ; i ++) {dp[i] = (dp[i] * s[L - a[i].p]) % mod;ans = (ans + dp[i]) % mod;}cout << ans;return 0;}```