当前位置:网站首页>Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
2022-07-28 17:09:00 【Code92007】
subject
time limit 20s,T(T<=100) Group example , common E(E<=100) Exercise times , Each exercise may require W(W<=100) Kind of barbell ,
The first i Tiandi j The number of barbell pieces required for each kind is Xij(0<=Xij<=100),
Put the barbell piece into a shape like 「 Stack 」 On the barbell rack ,

such as , The first day is AABA, The next day is AACCDD,
You need to put AABA, Bounce off A, Bounce off B,
And then put in C, Put in C, Put in D, Put in D, To get the barbell piece the next day
Finally, find the initial state of the barbell frame from empty , After exercise E Next time , Keep it empty ,
What is the minimum number of barbell pieces operated
Source of ideas
jiangly Code
Answer key
be aware , If the first [1,n] Some barbell pieces in this exercise are public ,
Then these barbell pieces can be directly padded under , First put , Finally take out , Then ignore these barbell pieces
Then consider divide and conquer , The first [l,r] The answer to this exercise can be [l,x] and [x+1,n] Get ,
Set the first [l,r] The barbell piece for this exercise is mn[l][r],
Is the first [l,r] Exercise times , It can be disassembled into ,
At first, put... In the stack mn[l][x] A barbell piece , Go ahead [l,x] Exercise times , After completion, play the stack and delete the barbell piece into mn[l][r] individual ,
Then pad barbell pieces so that the number of barbell pieces in the stack is mn[x+1][r] individual , Go ahead [x+1,r] Exercise times , Delete the barbell pieces after completion
The initial initialization length is 1 The range of , Its contribution is 2*mn[i][i], It means that the change of barbell piece is 0->mn[i][i]->0
Then when the intervals are merged , The change of barbell pieces before the merger is 0->mn[l][x]->0->mn[x+1][r]->0,
After the merger , The change of barbell piece is 0->mn[l][x]->mn[l][r]->mn[x+1][r]->0, That is, when consolidation occurs , Answer minus 2*mn[l][r]
Experience
Think of this public barbell piece trick 了 , But I still couldn't think of the interval in the end dp
I looked at the problems I had done , Discovery and hdu4283 You Are the One( Section DP) This question is very similar
The solution is based on jiangly It's written in code , The official solution is much the same .
Official explanation
dp[l][r] It's the second time [l,r] Exercise public barbell pieces ( The number is recorded as C[l,r]) Load the stack in advance , After exercising [l,r] Next time , Play the stack so that only this C[l,r] Minimum operation times of barbell pieces .
Consider enumerating an intermediate number of times x,dp[l][r]=min(dp[l][r],dp[l][x]+dp[x+1][r]+2*((C[l,x]-C[l,r])+(C[x+1,r]-C[l,r]))), Represents a process of disassembling into sub problems .
Exercise [l,r] These times , There are now public barbell pieces in the stack C[l,r] individual , Enter the stack first to turn the barbell pieces in the stack into C(l,x) individual , Go on with the second [l,x] Exercise times , Play the stack again to restore the barbell piece to C[l,r] individual , Re entering the stack turns the barbell piece into C[x+1,r] individual , Go on with the second [x+1,r] Exercise times , Play the stack again to restore the barbell piece to C[l,r] individual .
The final answer is dp[1][n]+2*C[1][n].
Or introduce empty elements 0、n+1, The final answer is dp[0][n+1].
Code
#include<bits/stdc++.h>
using namespace std;
const int N=105,INF=0x3f3f3f3f;
int t,n,m,dp[N][N],a[N][N],mn[N][N],now[N];
int main(){
scanf("%d",&t);
for(int ca=1;ca<=t;++ca){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
scanf("%d",&a[i][j]);
}
}
memset(mn,0,sizeof mn);
for(int l=1;l<=n;++l){
memset(now,INF,sizeof now);
for(int r=l;r<=n;++r){
for(int j=1;j<=m;++j){
now[j]=min(now[j],a[r][j]);
mn[l][r]+=now[j];
}
}
}
for(int i=1;i<=n;++i){
dp[i][i]=2*mn[i][i];
}
for(int len=2;len<=n;++len){
for(int l=1;l+len-1<=n;++l){
int r=l+len-1;
dp[l][r]=INF;
for(int k=l;k+1<=r;++k){
dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]-2*mn[l][r]);
}
}
}
printf("Case #%d: %d\n",ca,dp[1][n]);
}
return 0;
}边栏推荐
- Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
- MD5 encryption verification
- 【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)
- The 16th program design competition of Dalian University of Technology (Problem Solver)
- 记录ceph两个rbd删除不了的处理过程
- 3D建模工具Archicad 26全新发布
- Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings
- Ugui learning notes (VI) get the information of the clicked UI
- Do you really understand CMS garbage collector?
- mysql 最大建议行数2000w,靠谱吗?
猜你喜欢
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)

Do you really understand CMS garbage collector?

Easypoi multi sheet export by template

PostgreSQL每周新闻—2022年7月20日

综合设计一个OPPE主页--页面的售后服务
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

Alibaba cloud MSE supports go language traffic protection

HTAP comes at a price

: No such file or directory
随机推荐
记录开发问题
Easypoi --- excel file export
Reduce cycle complexity
Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
Outline and principle of structured design -- modularization
leetcode9. 回文数
MD5 encryption verification
Efficiency comparison of three methods for obtaining timestamp
SUSE Ceph 快速部署 – Storage6
Question making note 2 (add two numbers)
阿里云 MSE 支持 Go 语言流量防护
结构化设计的概要与原理--模块化
Unity shader uses rendered texture to achieve glass effect
Detailed steps for setting up SUSE storage6 environment – win10 + VMware Workstation
Ugui learning notes (I) rendering level
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
Add differential pairs and connections in Ad
MySQL installation tutorial
打造自组/安全/可控的LoRa网!Semtech首度回应“工信部新规”影响
leetcode647. 回文子串