当前位置:网站首页>[dynamic planning] p1220: interval DP: turn off the street lights
[dynamic planning] p1220: interval DP: turn off the street lights
2022-07-02 21:00:00 【muse_ age】



Turn off the section 【i,j】 Inside the lamp and at the end on the left ( The first i Turn off the light last ), This state can be transferred from two states :
(1) Turn off the section 【i+1,j】 And the end is i+1
f[i+1][j][0]+d[i,i+1]*p( p For the power and , That's the interval 【i+1,j】 The sum of numbers beyond , You can use prefixes and preprocessing )
(2) Turn off the section 【i+1,j】 And the end is j
f[i+1][j][1]+d[i,j]*p
Turn off the section 【i,j】 Inside the lamp and at the end on the right
initialization :
dp[c][c][0]=dp[c][c][1]=0(0 You can turn it off in seconds c Position light )
All others are initially INF( Because minimum value is required )
Be careful :
Algorithm problems are routine problems , Only do more and accumulate more , Only when you see new topics can you have ideas !
When doing a question , If not , You can see the solution !
expand :
Fill in the form :
Use the state transition equation and the previous state to deduce the state appearing in ( It is equivalent to knowing the known conditions , Fill in the answers )
Brush table method :
Take advantage of the current state , Push out the next related state .
Code :
#include<iostream>
#include<cstring>
using namespace std;
int n,c;
int x[51],p[51],sum[51],dp[51][51][2];
int main(){
cin>>n>>c;
sum[0]=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>p[i];
sum[i]=sum[i-1]+p[i];
}
memset(dp,0x3f,sizeof(dp));
dp[c][c][0]=dp[c][c][1]=0;
for(int i=c;i>=1;i--){
for(int j=i+1;j<=n;j++){
dp[i][j][0]=min(dp[i+1][j][0]+(x[i+1]-x[i])*(sum[n]-(sum[j]-sum[i])),dp[i+1][j][1]+(x[j]-x[i])*(sum[n]-(sum[j]-sum[i])));
dp[i][j][1]=min(dp[i][j-1][0]+(x[j]-x[i])*(sum[n]-(sum[j-1]-sum[i-1])),dp[i][j-1][1]+(x[j]-x[j-1])*(sum[n]-(sum[j-1]-sum[i-1])));
}
}
int res=0x3f;
res=min(dp[1][n][0],dp[1][n][1]);
cout<<res;
return 0;
} 边栏推荐
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- 【871. 最低加油次数】
- Research and Analysis on the current situation of China's clamping device market and forecast report on its development prospect
- BitSet complement
- Google Earth engine (GEE) - Landsat 9 image full band image download (Beijing as an example)
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
- GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
- Research Report on the overall scale, major manufacturers, major regions, products and applications of friction dampers in the global market in 2022
- Research Report on the overall scale, major manufacturers, major regions, products and applications of micro hydraulic cylinders in the global market in 2022
- [fluent] dart function (function composition | private function | anonymous function | function summary)
猜你喜欢

Jetson XAVIER NX上ResUnet-TensorRT8.2速度与显存记录表(后续不断补充)
![[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)](/img/80/215499c66243d5a4453d8e6206c012.jpg)
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)

Properties of expectation and variance

An analysis of the past and present life of the meta universe

Attack and defense world PWN question: Echo

B-end e-commerce - reverse order process

Web3js method to obtain account information and balance

Add two numbers of leetcode

C language linked list -- to be added

GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
随机推荐
【Kubernetes系列】kubeadm reset初始化前后空间、内存使用情况对比
Codeworks global round 19 (CF 1637) a ~ e problem solution
1005 spell it right (20 points) "PTA class a exercise"
Want to ask, is there any discount for opening an account now? Is it safe to open an account online?
For (Auto A: b) and for (Auto & A: b) usage
Spark source code compilation, cluster deployment and SBT development environment integration in idea
How to do interface testing? After reading this article, it will be clear
An analysis of the past and present life of the meta universe
JS modularization
[error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
5 environment construction spark on yarn
kernel_ uaf
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of signal distributors in the global market in 2022
Research Report on the overall scale, major manufacturers, major regions, products and applications of outdoor vacuum circuit breakers in the global market in 2022
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)
[real case] trap of program design - beware of large data
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of multi-channel signal conditioners in the global market in 2022
Outsourcing for three years, abandoned
Structured text language XML
Research and Analysis on the current situation of China's clamping device market and forecast report on its development prospect