P4141 消失之物
容斥:
前者为
保证转移
/*
* @Author: crab-in-the-northeast
* @Date: 2023-06-27 20:51:50
* @Last Modified by: crab-in-the-northeast
* @Last Modified time: 2023-06-27 21:29:30
*/
#include <bits/stdc++.h>
inline int read() {
int x = 0;
bool f = true;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = false;
for (; isdigit(ch); ch = getchar())
x = (x << 1) + (x << 3) + ch - '0';
return f ? x : (~(x - 1));
}
const int N = 2005, M = 2005;
int f[N][M], g[N][M];
const int mod = 10;
int a[N];
signed main() {
int n = read(), m = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
f[i][j] = f[i - 1][j];
if (j >= a[i])
(f[i][j] += f[i - 1][j - a[i]]) %= 10;
}
}
for (int i = 1; i <= n; ++i, puts("")) {
for (int j = 0; j <= m; ++j) {
g[i][j] = f[n][j];
if (j >= a[i])
(g[i][j] += 10 - g[i][j - a[i]]) %= 10;
if (j)
putchar(g[i][j] ^ '0');
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效