当前位置:网站首页>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;
}
边栏推荐
- P6183 [USACO10MAR] The Rock Game S
- Cartoon: what are the attributes of a good programmer?
- Number protection AXB function! (essence)
- 漫画:优秀的程序员具备哪些属性?
- Aike AI frontier promotion (7.5)
- Mysql---- function
- Detailed explanation of QT creator breakpoint debugger
- Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
- Your childhood happiness was contracted by it
- [recruitment position] infrastructure software developer
猜你喜欢

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

Bugku's steganography

社区团购撤城“后遗症”

Fr exercise topic --- comprehensive question

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle

Anti shake and throttling

Database learning - Database Security

美团优选管理层变动:老将刘薇调岗,前阿里高管加盟

MySQL----函数

Misc Basic test method and knowledge points of CTF
随机推荐
keep-alive
easyOCR 字符识别
社区团购撤城“后遗症”
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
Thymeleaf uses background custom tool classes to process text
Mongdb learning notes
[recruitment position] Software Engineer (full stack) - public safety direction
Number protection AXB function! (essence)
ICML 2022 | explore the best architecture and training method of language model
你童年的快乐,都是被它承包了
爱可可AI前沿推介(7.5)
CODING DevSecOps 助力金融企业跑出数字加速度
Redis distributed lock principle and its implementation with PHP (1)
Cartoon: programmers don't repair computers!
Easyocr character recognition
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
Redis distributed lock principle and its implementation with PHP (2)
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
qt creater断点调试程序详解