当前位置:网站首页>[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;
}
边栏推荐
- Web3js method to obtain account information and balance
- 现在券商的优惠开户政策什么?实际上网上开户安全么?
- Burp install license key not recognized
- 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
- 笔记本安装TIA博途V17后出现蓝屏的解决办法
- ROS learning (10): ROS records multiple topic scripts
- rwctf2022_ QLaaS
- How to do interface testing? After reading this article, it will be clear
- Sword finger offer (II) -- search in two-dimensional array
- [error record] the command line creates an error pub get failed (server unavailable) -- attempting retry 1 in 1 second
猜你喜欢
CRM Customer Relationship Management System
Review of the latest 2022 research on "deep learning methods for industrial defect detection"
kernel tty_ struct
【QT】QPushButton创建
burp 安装 license key not recognized
Solution to blue screen after installing TIA botu V17 in notebook
Interested parties add me for private chat
Postman interface test practice, these five questions you must know
Complete example of pytorch model saving +does pytorch model saving only save trainable parameters? Yes (+ solution)
[real case] trap of program design - beware of large data
随机推荐
[fluent] dart function (function composition | private function | anonymous function | function summary)
Write the content into the picture with type or echo and view it with WinHex
Activation function - relu vs sigmoid
kernel_ uaf
Summary of interview experience, escort your offer, full of knowledge points
Research Report on the overall scale, major manufacturers, major regions, products and applications of building automation power meters in the global market in 2022
[question brushing diary] classic questions of dynamic planning
Redis sentinel cluster working principle and architecture deployment # yyds dry goods inventory #
股票开户要找谁?手机开户是安全么?
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
Sometimes only one line of statements are queried, and the execution is slow
How to do interface testing? After reading this article, it will be clear
Review of the latest 2022 research on "deep learning methods for industrial defect detection"
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of signal distributors in the global market in 2022
【Hot100】23. Merge K ascending linked lists
Research Report on the overall scale, major manufacturers, major regions, products and applications of outdoor vacuum circuit breakers in the global market in 2022
JS modularization
Google Earth Engine(GEE)——Landsat 9影像全波段影像下载(北京市为例)
Use graalvm native image to quickly expose jar code as a native shared library
Is it safe to buy funds on securities accounts? Where can I buy funds