当前位置:网站首页>骑士战胜魔王(背包&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命令之- jmap:导出内存映像文件&内存使用情况
- jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取
- Data storage 3
- Career experience feedback to novice programmers
- JVM命令之 jstack:打印JVM中线程快照
- What is make makefile cmake qmake and what is the difference?
- Apple CMS V10 template /mxone Pro adaptive film and television website template
- SQL Server 2008 各种DateTime的取值范围
- 那些自损八百的甲方要求
- What EDA companies are there in China?
猜你喜欢
![[云原生]微服务架构是什么?](/img/84/a0ec68646083f3539aa39ad9d98749.png)
[云原生]微服务架构是什么?

C note 13

DC-7靶机

Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition

JVM命令之 jstat:查看JVM统计信息

laravel 使用腾讯云 COS5全教程

进程间通信之共享内存
![[SQL practice] a SQL statistics of epidemic distribution across the country](/img/ba/639a23d87094d24572a69575b565b9.png)
[SQL practice] a SQL statistics of epidemic distribution across the country
![[InstallShield] Introduction](/img/df/4522d06510ff918d00659b8358368f.jpg)
[InstallShield] Introduction
![[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core](/img/19/1a6d43c39f2cf810ba754ea9674426.png)
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
随机推荐
Laravel uses Tencent cloud cos5 full tutorial
【FPGA教程案例13】基于vivado核的CIC滤波器设计与实现
Add salt and pepper noise or Gaussian noise to the picture
Cloud acceleration helps you effectively solve attack problems!
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
You don't know the complete collection of recruitment slang of Internet companies
Ctfshow-- common posture
话说SQLyog欺骗了我!
postgresql 数据库 timescaledb 函数time_bucket_gapfill()报错解决及更换 license
On the discrimination of "fake death" state of STC single chip microcomputer
Solve pod install error: FFI is an incompatible architecture
PTA 天梯赛练习题集 L2-004 搜索树判断
JVM命令之 jstack:打印JVM中线程快照
【SQL实战】一条SQL统计全国各地疫情分布情况
[cloud native] what is the microservice architecture?
Change the original style of UI components
搞懂fastjson 对泛型的反序列化原理
[云原生]微服务架构是什么?
云加速,帮助您有效解决攻击问题!