当前位置:网站首页>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;
}
边栏推荐
- 如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?
- 980. Different path III DFS
- vim映射大K
- Storage of dental stem cells (to be continued)
- SAP Spartacus checkout 流程的扩展(extend)实现介绍
- 解决pod install报错:ffi is an incompatible architecture
- Markdown 并排显示图片
- 绕过open_basedir
- Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
- jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取
猜你喜欢

当我们谈论不可变基础设施时,我们在谈论什么

如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?

"Parse" focalloss to solve the problem of data imbalance

C note 13

雷特智能家居龙海祁:从专业调光到全宅智能,20年专注成就专业

Ctfshow-- common posture

【FPGA教程案例14】基于vivado核的FIR滤波器设计与实现

绕过open_basedir

你不知道的互联网公司招聘黑话大全

On the discrimination of "fake death" state of STC single chip microcomputer
随机推荐
Calculation model FPS
Qtthread, one of many methods of QT multithreading
骑士战胜魔王(背包&dp)
Introduction to the extension implementation of SAP Spartacus checkout process
【SQL实战】一条SQL统计全国各地疫情分布情况
Talking about reading excel with POI
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
Jstat pour la commande JVM: voir les statistiques JVM
On the discrimination of "fake death" state of STC single chip microcomputer
测试开发基础,教你做一个完整功能的Web平台之环境准备
When we talk about immutable infrastructure, what are we talking about
Understand the deserialization principle of fastjson for generics
MFC BMP sets the resolution of bitmap, DPI is 600 points, and gdiplus generates labels
Developers don't miss it! Oar hacker marathon phase III chain oar track registration opens
JVM监控及诊断工具-命令行篇
A very good JVM interview question article (74 questions and answers)
QT console output in GUI applications- Console output in a Qt GUI app?
Jcmd of JVM command: multifunctional command line
VScode进行代码补全
Niuke Xiaobai monthly race 52 E. sum logarithms in groups (two points & inclusion and exclusion)