当前位置:网站首页>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;
}
边栏推荐
- Leetcode: Shortest Word Distance II
- PHP high concurrency and large traffic solution (PHP interview theory question)
- ionic cordova项目修改插件
- Mongdb learning notes
- GPS original coordinates to Baidu map coordinates (pure C code)
- Can I pass the PMP Exam in 20 days?
- [recruitment position] Software Engineer (full stack) - public safety direction
- I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- Bubble sort, insert sort
猜你喜欢
Talking about how dataset and dataloader call when loading data__ getitem__ () function
Detailed explanation of QT creator breakpoint debugger
12 MySQL interview questions that you must chew through to enter Alibaba
Bugku telnet
Install and configure Jenkins
ionic cordova项目修改插件
华为哈勃化身硬科技IPO收割机
[JVM] operation instruction
Huiyuan, 30, is going to have a new owner
Ionic Cordova project modification plug-in
随机推荐
Thymeleaf uses background custom tool classes to process text
Common interview questions about swoole
swiper. JS to achieve barrage effect
漫画:程序员不是修电脑的!
P1451 calculate the number of cells / 1329: [example 8.2] cells
Ten billion massage machine blue ocean, difficult to be a giant
超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
百亿按摩仪蓝海,难出巨头
把 ”中台“ 的思想迁移到代码中去
华为哈勃化身硬科技IPO收割机
Ctfshow web entry explosion
Talking about how dataset and dataloader call when loading data__ getitem__ () function
B站做短视频,学抖音死,学YouTube生?
P6183 [USACO10MAR] The Rock Game S
ionic cordova项目修改插件
ICML 2022 | 探索语言模型的最佳架构和训练方法
I spring and autumn blasting-2
How to paste the contents copied by the computer into mobaxterm? How to copy and paste
wxml2canvas
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking