当前位置:网站首页>[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;
} 边栏推荐
- 什么叫在线开户?现在网上开户安全么?
- Number of DP schemes
- Roommate, a king of time, I took care of the C language structure memory alignment
- 2021 software security report: open source code, happiness and disaster depend on each other?
- Internal/validators js:124 throw new ERR_ INVALID_ ARG_ Type (name, 'string', value) -- solution
- 2021 v+ Quanzhen internet global innovation and Entrepreneurship Challenge, one of the top ten audio and video scene innovation and application pioneers
- Implementing yolox from scratch: dataset class
- 想请教一下,究竟有哪些劵商推荐?手机开户是安全么?
- [internship] solve the problem of too long request parameters
- Share several map bed websites for everyone to share pictures
猜你喜欢

Postman interface test practice, these five questions you must know
![[internship] solve the problem of too long request parameters](/img/42/413cf867f0cb34eeaf999f654bf02f.png)
[internship] solve the problem of too long request parameters

Common routines of compressed packets in CTF

笔记本安装TIA博途V17后出现蓝屏的解决办法

疫情封控65天,我的居家办公心得分享 | 社区征文
In depth understanding of modern web browsers (I)

6 pyspark Library

Spark source code compilation, cluster deployment and SBT development environment integration in idea

Customized Huawei hg8546m restores Huawei's original interface

数据库模式笔记 --- 如何在开发中选择合适的数据库+关系型数据库是谁发明的?
随机推荐
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
Share several map bed websites for everyone to share pictures
1007 maximum subsequence sum (25 points) "PTA class a exercise"
In depth understanding of modern web browsers (I)
When Valentine's Day falls on Monday
Research Report on the overall scale, major manufacturers, major regions, products and applications of capacitive voltage transformers in the global market in 2022
【Hot100】21. Merge two ordered linked lists
Research Report on the overall scale, major manufacturers, major regions, products and applications of sliding door dampers in the global market in 2022
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of the inverted front fork of the global market in 2022
SBT tutorial
Interested parties add me for private chat
An analysis of the past and present life of the meta universe
What is online account opening? Is it safe to open an account online now?
Jetson XAVIER NX上ResUnet-TensorRT8.2速度與顯存記錄錶(後續不斷補充)
股票开户要找谁?手机开户是安全么?
Structured text language XML
Select function
Welfare | Hupu isux11 Anniversary Edition is limited to hand sale!
In the era of consumer Internet, a few head platforms have been born
Number of DP schemes