当前位置:网站首页>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;
}
边栏推荐
- Cf:c. column swapping [sort + simulate]
- SAP Spartacus checkout 流程的扩展(extend)实现介绍
- Database notes 04
- Find duplicate email addresses
- 对称的二叉树【树的遍历】
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- Experience sharing of contribution of "management world"
- @pathvariable 和 @Requestparam的详细区别
- SubGHz, LoRaWAN, NB-IoT, 物联网
- Laravel uses Tencent cloud cos5 full tutorial
猜你喜欢

「解析」FocalLoss 解决数据不平衡问题

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

为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾

Ideas of high concurrency and high traffic seckill scheme
![A freshman's summary of an ordinary student [I don't know whether we are stupid or crazy, but I know to run forward all the way]](/img/fd/7223d78fff54c574260ec0da5f41d5.png)
A freshman's summary of an ordinary student [I don't know whether we are stupid or crazy, but I know to run forward all the way]

Laravel uses Tencent cloud cos5 full tutorial

postgresql 数据库 timescaledb 函数time_bucket_gapfill()报错解决及更换 license

JMeter's own functions are not enough? Why don't you develop one yourself

Say sqlyog deceived me!

【GNN】图解GNN: A gentle introduction(含视频)
随机推荐
How to keep accounts of expenses in life
Swagger3 configuration
高并发大流量秒杀方案思路
laravel 使用腾讯云 COS5全教程
Experience of Niuke SQL
VMware安装后打开就蓝屏
开发者别错过!飞桨黑客马拉松第三期链桨赛道报名开启
C. colonne Swapping [tri + Simulation]
你不知道的互联网公司招聘黑话大全
PowerPivot - DAX (function)
Jinfo of JVM command: view and modify JVM configuration parameters in real time
Subghz, lorawan, Nb IOT, Internet of things
Markdown 并排显示图片
Career experience feedback to novice programmers
Test the foundation of development, and teach you to prepare for a fully functional web platform environment
Deep clustering: joint optimization of depth representation learning and clustering
Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
QT console output in GUI applications- Console output in a Qt GUI app?
window下面如何安装swoole