当前位置:网站首页>[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;
} 边栏推荐
- 【Hot100】21. Merge two ordered linked lists
- ctf-HCTF-Final-Misc200
- Implementing yolox from scratch: dataset class
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of sound quality head simulators in the global market in 2022
- BitSet complement
- Write the content into the picture with type or echo and view it with WinHex
- 1005 spell it right (20 points) "PTA class a exercise"
- Sword finger offer (I) -- handwriting singleton mode
- 现在券商的优惠开户政策什么?实际上网上开户安全么?
- Don't you want to have a face-to-face communication with cloud native and open source experts? (including benefits
猜你喜欢

How to realize the function of detecting browser type in Web System

Review of the latest 2022 research on "deep learning methods for industrial defect detection"

【Hot100】21. Merge two ordered linked lists

qwb2018_ core kernel_ rop

Internal/validators js:124 throw new ERR_ INVALID_ ARG_ Type (name, 'string', value) -- solution
![[real case] trap of program design - beware of large data](/img/bd/d72cc5ce23756cea873c9ced6b642a.jpg)
[real case] trap of program design - beware of large data

Use graalvm native image to quickly expose jar code as a native shared library

rwctf2022_ QLaaS

26 FPS video super-resolution model DAP! Output 720p Video Online

Activation function - relu vs sigmoid
随机推荐
Research Report on the overall scale, major manufacturers, major regions, products and applications of swivel chair gas springs in the global market in 2022
想请教一下,究竟有哪些劵商推荐?手机开户是安全么?
Properties of expectation and variance
[fluent] dart generic (generic class | generic method | generic with specific type constraints)
【Hot100】23. Merge K ascending linked lists
[error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
Spark source code compilation, cluster deployment and SBT development environment integration in idea
Research Report on the overall scale, major manufacturers, major regions, products and applications of building automation power meters in the global market in 2022
This team with billions of data access and open source dreams is waiting for you to join
B-end e-commerce - reverse order process
Share several map bed websites for everyone to share pictures
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of precoated metallic coatings in the global market in 2022
Import a large amount of data to redis in shell mode
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
The first of the classic quotations of correspondents is heartbreaking
Google Earth engine (GEE) - Landsat 9 image full band image download (Beijing as an example)
rwctf2022_ QLaaS
Roommate, a king of time, I took care of the C language structure memory alignment
[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
A river of spring water flows eastward