当前位置:网站首页>Knight defeats demon king (Backpack & DP)
Knight defeats demon king (Backpack & DP)
2022-07-07 06:18:00 【Harris-H】
The knight defeated the demon king ( knapsack &dp)
Because the plan is different , It depends on the energy and difference used by a knight .
Therefore, we consider using backpacks to deal with the energy used by each Knight i i i The biggest damage , When seeking the maximum, in order to include all cases .
Then proceed dp, Make f ( i , j ) f(i,j) f(i,j) Before presentation i i i Knights caused j j j Number of schemes for point damage .
Specially , f ( i , m ) f(i,m) f(i,m) Before presentation i i i Knights cause greater than or equal to j j j Number of schemes for point damage .
Then proceed dp that will do .
Time complexity : 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; /// initialization dp Array
for(int i = 0; i < s; i ++) {
/// Find out the maximum attack power that each energy consumption of the current knight can cause
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 Total time complexity of knights : sum(s) * 3000
for(int i = 0; i <= 3000; i ++) {
if(ff[i] == 0 && i != 0) continue; /// Some values cannot be represented , The magnitude of the value that can be represented is sum(b)
if(ff[i] > m) ff[i] = m; /// Attack overflow processing
for(int j = 0; j < ff[i]; j ++) /// Here is the number of schemes in the attack overflow part , It needs to be calculated separately
fans[ttf][m] = (fans[ttf][m] + fans[ttf - 1][m - j]) % mod;
for(int j = m; j >= ff[i]; j --) /// This for And the one above for The total time complexity of is : sum(b) * m
fans[ttf][j] = (fans[ttf][j] + fans[ttf - 1][j - ff[i]]) % mod;
} /// n The total time complexity of a knight here : n * 3000
} /// Total time complexity : sum(s) * 3000 + n * 3000 + sum(b) * m
cout << fans[n][m];
}
int main() {
// int ttx; cin >> ttx; while(ttx --)
solved();
return 0;
}
边栏推荐
- On the discrimination of "fake death" state of STC single chip microcomputer
- Experience of Niuke SQL
- How to keep accounts of expenses in life
- Bypass open_ basedir
- 骑士战胜魔王(背包&dp)
- SubGHz, LoRaWAN, NB-IoT, 物联网
- C. colonne Swapping [tri + Simulation]
- Sequential storage of stacks
- Subghz, lorawan, Nb IOT, Internet of things
- VScode进行代码补全
猜你喜欢

laravel 使用腾讯云 COS5全教程

DC-7靶机

@Detailed differences between pathvariable and @requestparam

CloudCompare-点对选取

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

直击2022ECDC萤石云开发者大会:携手千百行业加速智能升级
![[FPGA] EEPROM based on I2C](/img/28/f4f2efda4b5feb973c9cf07d9d908f.jpg)
[FPGA] EEPROM based on I2C

Find duplicate email addresses

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

Chain storage of stack
随机推荐
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
On the discrimination of "fake death" state of STC single chip microcomputer
Subghz, lorawan, Nb IOT, Internet of things
Sequential storage of stacks
LM小型可编程控制器软件(基于CoDeSys)笔记二十三:伺服电机运行(步进电机)相对坐标转换为绝对坐标
Laravel uses Tencent cloud cos5 full tutorial
jvm命令之 jcmd:多功能命令行
jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取
[Shell]常用shell命令及测试判断语句总结
980. Different path III DFS
当我们谈论不可变基础设施时,我们在谈论什么
基于ADAU1452的DSP及DAC音频失真分析
ETCD数据库源码分析——从raftNode的start函数说起
谷歌 Chrome 浏览器发布 103.0.5060.114 补丁修复 0-day 漏洞
Cloud acceleration helps you effectively solve attack problems!
Dc-7 target
生活中的开销,怎么记账合适
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
@pathvariable 和 @Requestparam的详细区别
Deep clustering: joint optimization of depth representation learning and clustering