当前位置:网站首页>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;
}
边栏推荐
- R 熵权法计算权重及综合得分
- Severlet learning foundation
- GPS原始坐标转百度地图坐标(纯C代码)
- qt creater断点调试程序详解
- Usage and usage instructions of JDBC connection pool
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- 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
- 当代人的水焦虑:好水究竟在哪里?
- Jmeter性能测试:ServerAgent资源监控
- Common PHP interview questions (1) (written PHP interview questions)
猜你喜欢

【jvm】运算指令

Ctfshow web entry explosion

Crud de MySQL

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

Super wow fast row, you are worth learning!

Usage and usage instructions of JDBC connection pool
![P1451 calculate the number of cells / 1329: [example 8.2] cells](/img/c4/c62f3464608dbd6cf776c2cd7f07f3.png)
P1451 calculate the number of cells / 1329: [example 8.2] cells

Common PHP interview questions (1) (written PHP interview questions)

爱可可AI前沿推介(7.5)

Number protection AXB function! (essence)
随机推荐
The elimination strategy of redis
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
Ionic Cordova project modification plug-in
Coding devsecops helps financial enterprises run out of digital acceleration
Select sort and bubble sort
Cartoon: what are the attributes of a good programmer?
JS bright blind your eyes date selector
Appium自动化测试基础 — APPium基础操作API(二)
Ctfshow web entry explosion
Crud of MySQL
R 熵权法计算权重及综合得分
wxml2canvas
Ctfshow web entry information collection
Bugku's Eval
Common redis data types and application scenarios
华为哈勃化身硬科技IPO收割机
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
qt creater断点调试程序详解
Bugku easy_ nbt
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues