当前位置:网站首页>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;
}
边栏推荐
- Install PHP extension spoole
- "Sequelae" of the withdrawal of community group purchase from the city
- The elimination strategy of redis
- Go learning ----- relevant knowledge of JWT
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
- [JVM] operation instruction
- MySQL表字段调整
- I spring and autumn blasting-1
- Bugku's Ah Da
猜你喜欢

Huawei Hubble incarnation hard technology IPO harvester

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

Super wow fast row, you are worth learning!

Ctfshow web entry information collection

I spring and autumn blasting-2

机器学习笔记 - 灰狼优化

Thymeleaf uses background custom tool classes to process text

Bugku's Ah Da

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

Number protection AXB function! (essence)
随机推荐
Creation and optimization of MySQL index
go学习 ------jwt的相关知识
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
swiper. JS to achieve barrage effect
华为哈勃化身硬科技IPO收割机
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
Bugku easy_ nbt
Easyocr character recognition
Bugku's eyes are not real
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
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
P6183 [USACO10MAR] The Rock Game S
Interpretation of Apache linkage parameters in computing middleware
episodic和batch的定义
1330:【例8.3】最少步数
How to paste the contents copied by the computer into mobaxterm? How to copy and paste
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues
MySQL 巨坑:update 更新慎用影响行数做判断!!!
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Usage and usage instructions of JDBC connection pool