当前位置:网站首页>骑士战胜魔王(背包&dp)
骑士战胜魔王(背包&dp)
2022-07-07 01:25:00 【Harris-H】
骑士战胜魔王(背包&dp)
因为方案不同,取决于一个骑士使用的能量和不同。
因此我们考虑先用背包处理出每个骑士使用能量 i i i的最大伤害,求最大时为了包括所有情况。
然后进行dp,令 f ( i , j ) f(i,j) f(i,j)表示前 i i i个骑士造成 j j j 点伤害的方案数。
特别地, f ( i , m ) f(i,m) f(i,m) 表示前 i i i个骑士造成大于等于 j j j点伤害的方案数。
然后进行dp即可。
时间复杂度: O ( n × 3000 ) O(n\times 3000) O(n×3000)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
int n, m;
int fans[3009][3009], ff[3009];
int a[3009], b[3009];
void solved() {
cin >> n >> m;
fans[0][0] = 1;
int s;
for(int ttf = 1; ttf <= n; ttf ++) {
cin >> s;
for(int i = 0; i < s; i ++) cin >> a[i];
for(int i = 0; i < s; i ++) cin >> b[i];
for(int i = 0; i <= 3000; i ++) ff[i] = 0; /// 初始化 dp 数组
for(int i = 0; i < s; i ++) {
/// 求出当前骑士花费的每种能量消耗可以造成的最大攻击力
for(int j = 3000; j >= b[i]; j --) {
if(ff[j - b[i]] || j - b[i] == 0)
ff[j] = max(ff[j - b[i]] + a[i], ff[j]);
}
} /// n个骑士总时间复杂度: sum(s) * 3000
for(int i = 0; i <= 3000; i ++) {
if(ff[i] == 0 && i != 0) continue; /// 有些值无法被表示,能被表示的值的量级为 sum(b)
if(ff[i] > m) ff[i] = m; /// 攻击力溢出处理
for(int j = 0; j < ff[i]; j ++) /// 这里是攻击力溢出部分的方案数,需要单独计算
fans[ttf][m] = (fans[ttf][m] + fans[ttf - 1][m - j]) % mod;
for(int j = m; j >= ff[i]; j --) /// 这个 for 和上面一个 for 的总时间复杂度均为: sum(b) * m
fans[ttf][j] = (fans[ttf][j] + fans[ttf - 1][j - ff[i]]) % mod;
} /// n个骑士这里的总时间复杂度: n * 3000
} /// 总时间复杂度: sum(s) * 3000 + n * 3000 + sum(b) * m
cout << fans[n][m];
}
int main() {
// int ttx; cin >> ttx; while(ttx --)
solved();
return 0;
}
边栏推荐
- JVM command - jmap: export memory image file & memory usage
- What is make makefile cmake qmake and what is the difference?
- Reading notes of Clickhouse principle analysis and Application Practice (6)
- SAP Spartacus checkout 流程的扩展(extend)实现介绍
- window下面如何安装swoole
- 测试开发基础,教你做一个完整功能的Web平台之环境准备
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- Oracle迁移中关于大容量表使用数据泵(expdp、impdp)导出导入容易出现的问题和注意事项
- Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
- ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the
猜你喜欢

Apple CMS V10 template /mxone Pro adaptive film and television website template

693. 行程排序

Question 102: sequence traversal of binary tree

POI excel export, one of my template methods

老板总问我进展,是不信任我吗?(你觉得呢)
![C. colonne Swapping [tri + Simulation]](/img/0e/64d17980d3ec0051cdfb5fdb34e119.png)
C. colonne Swapping [tri + Simulation]

Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)

JVM command - jmap: export memory image file & memory usage

cf:C. Column Swapping【排序 + 模擬】

Career experience feedback to novice programmers
随机推荐
你不知道的互联网公司招聘黑话大全
What is make makefile cmake qmake and what is the difference?
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
JMeter's own functions are not enough? Why don't you develop one yourself
CMD permanently delete specified folders and files
JVM命令之 jstat:查看JVM統計信息
计算模型 FPS
目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
3428. 放苹果
PTA ladder game exercise set l2-004 search tree judgment
解决pod install报错:ffi is an incompatible architecture
From "running distractor" to data platform, Master Lu started the road of evolution
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
Check point: the core element for enterprises to deploy zero trust network (ztna)
Career experience feedback to novice programmers
软件测试知识储备:关于「登录安全」的基础知识,你了解多少?
Introduction to the extension implementation of SAP Spartacus checkout process
那些自损八百的甲方要求
Chain storage of stack