20241014总结
true
40pts
设
70pts
考虑在什么条件下才能够转移,很明显转移的
100pts
发现这样枚举左右端点是无法继续优化下去了,于是考虑将左右端点拆开进行动态规划,设
思考转移方程,需要用到容斥,
#include<iostream>
#define int long long
using namespace std;
inline int read(){
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9'){
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9'){
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
const int N = 5e3 + 10, mod = 998244353;
int n, m, ans;
int f[N], g[N], sf[N], sumf[N], sg[N], sumg[N];
signed main(){
freopen("true.in", "r", stdin);
freopen("true.out", "w", stdout);
n = read(), m = read();
for (int i = 1; i <= m; i++) f[i] = i, g[i] = m - i + 1;
for (int i = 2; i <= n; i++){
for (int j = 1; j <= m; j++) sf[j] = (sf[j - 1] + f[j]) % mod, sumf[j] = (sumf[j - 1] + sf[j]) % mod;
for (int j = 1; j <= m; j++) sg[j] = (sg[j - 1] + g[j]) % mod;
for (int j = m; j >= 1; j--) sumg[j] = (sumg[j + 1] + (sg[m] - sg[j - 1] + mod) % mod) % mod;
for (int j = 1; j <= m; j++) f[j] = (j * sg[j] % mod - sumf[j - 1] + mod) % mod;
for (int j = 1; j <= m; j++) g[j] = ((m - j + 1) * ((sf[m] - sf[j - 1] + mod) % mod) % mod - sumg[j + 1] + mod) % mod;
}
for (int i = 1; i <= m; i++) ans = (ans + f[i]) % mod;
cout << ans;
return 0;
}
light
只会暴力。
magician
枚举
hand
不会。
本文作者:bryce蒟蒻的小窝
本文链接:https://www.cnblogs.com/bryceyyds/p/18468438
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步