当前位置:网站首页>Explanation report of the explosion
Explanation report of the explosion
2022-07-05 15:25:00 【wch(】
The explosion's runes and cards are full of explanation reports
label : Dynamic programming
source : Cattle from 
Their thinking :
The obvious knapsack problem
But observe again a,b Data range of , I can't drive that big dp Array
This inspires us to optimize , Because the title requires magic, the total cost is k Multiple
We can spend magic power on every data k modulus
Use dp[][j] Save directly in After taking the mold, the sum of magic is j The greatest power of time
Then the dynamic transfer equation :
dp[i][j] = max(dp[i-1][j],dp[i-1][((j-a)%k+k)%k]+b);
After doing this, I found that it is the same as the problem of nine people and nine doors in nine hours , It's a pity that I didn't do it during the game
Code implementation :
#include <bits/stdc++.h>
using namespace std;
long long dp[1050][1050];
int main(){
int n,k;
cin>>n>>k;
int a,b;
memset(dp,-0x3f,sizeof(dp));
dp[0][0]=0;
for(int i=1;i<=n;i++){
cin>>a>>b;
for(int j=0;j<k;j++){
dp[i][j] = max(dp[i-1][j],dp[i-1][((j-a)%k+k)%k]+b);
}
}
long long ans = dp[n][0];
if(ans<=0) ans=-1;
cout<<ans<<endl;
return 0;
}
边栏推荐
- ICML 2022 | explore the best architecture and training method of language model
- 市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
- Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
- Jmeter性能测试:ServerAgent资源监控
- [JVM] operation instruction
- Thymeleaf uses background custom tool classes to process text
- ionic cordova项目修改插件
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- DVWA range clearance tutorial
- Optional parameters in the for loop
猜你喜欢

Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP

MySQL----函数

CODING DevSecOps 助力金融企业跑出数字加速度

Number protection AXB function! (essence)

百亿按摩仪蓝海,难出巨头

数据库学习——数据库安全性

Ctfshow web entry explosion

"Sequelae" of the withdrawal of community group purchase from the city

Select sort and bubble sort

市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
随机推荐
First PR notes
Misc Basic test method and knowledge points of CTF
Reasons and solutions for redis cache penetration and cache avalanche
Good article inventory
当代人的水焦虑:好水究竟在哪里?
Anaconda uses China University of science and technology source
Talking about how dataset and dataloader call when loading data__ getitem__ () function
Common PHP interview questions (1) (written PHP interview questions)
Calculate weight and comprehensive score by R entropy weight method
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
Ten billion massage machine blue ocean, difficult to be a giant
Common MySQL interview questions
Magic methods and usage in PHP (PHP interview theory questions)
lvgl 显示图片示例
数学建模之层次分析法(含MATLAB代码)
Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
MySQL表字段调整
P1451 calculate the number of cells / 1329: [example 8.2] cells