当前位置:网站首页>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;
}边栏推荐
- 阿里云 MSE 支持 Go 语言流量防护
- Some suggestions on Oracle SQL tuning
- 传英伟达已与软银展开会谈,将出价超过320亿美元收购Arm
- Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)
- HTAP comes at a price
- Best cow fences solution
- Unity shader realizes mirror effect with rendered texture
- Unity3d shader achieves ablation effect
- Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
- Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
猜你喜欢
![[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)

【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导

在AD中添加差分对及连线

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands

RE14: reading paper illsi interpretable low resource legal decision making

Realization of reflection and refraction effect in unity shader cube texture

技术分享 | 误删表以及表中数据,该如何恢复?

Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings

Games101 section 13 ray tracing notes

Re11: read EPM legal judgment prediction via event extraction with constraints
随机推荐
Unity editor learning (I) using features to change the display of fields in components
Go language slow entry - process control statement
Unity3d shader achieves ablation effect
深入理解 DeepSea 和 Salt 部署工具 – Storage6
MySQL installation tutorial
【深度学习】:《PyTorch入门到项目实战》第八天:权重衰退(含源码)
Games101 assignment04 job 04
【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)
Some opinions on bug handling
How should I understand craft
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
The longest substring of sword finger offer without repeated characters
MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
我该如何理解工艺
mysql 最大建议行数2000w,靠谱吗?
: No such file or directory
Outline and principle of structured design -- modularization
Hikvision responded to the impact of the 'US ban': there are options for the components currently used
Record the processing process of CEPH two RBDS that cannot be deleted