Dynamic Programming (decision Monotonic Optimization): Bzoj 4518 [Sdoi2016] Journey

Source: Internet
Author: User

4518: [Sdoi2016] Journey time limit:10 Sec Memory limit:256 MB
submit:532 solved:337
[Submit] [Status] [Discuss] Descriptionpine began the journey from the s to the land of T. The road from S to T can be divided into n segments, and the dividing point of the adjacent two sections is provided with a rest station. Pine plans to reach T-land with M-day. In addition to the outer m, every night pine must stay overnight at the rest station. Therefore, a certain road must be completed on the same day. Pine wants to walk the length of the road as closely as possible every day, so he wants the variance of the length of the road to go every day as small as possible. Help Pine to find out what the minimum variance is. Setting the variance is V, which proves that vxm^2 is an integer. In order to avoid accuracy error, output vxm^2 when output result. Input first row two number n, M. Second row n number, indicating the length of the N-segment output

A number, the minimum variance multiplied by the value of m^2

Sample Input5 2
1 2 5) 8 6Sample Output $HINT

1≤n≤3000, ensure that the total distance from S to T is not more than 30000

It's still very simple.

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn=3010;6 Long LongDP[MAXN][MAXN],S[MAXN];7 intN,M,P[MAXN][MAXN];8 intMain () {9 #ifndef Online_judgeTenFreopen ("menci_journey.in","R", stdin); OneFreopen ("Menci_journey.out","W", stdout); A #endif -scanf"%d%d",&n,&m); -Memset (DP, the,sizeof(DP)); the      for(intI=1; i<=n;i++){ -scanf"%lld",&s[i]); -s[i]+=s[i-1]; -     } +dp[0][0]=0; -      for(intk=1; k<=m;k++){ +          for(inti=k;i<=n;i++){ A              for(intj=p[k][i-1];j<i;j++){ at                 if(dp[k][i]>dp[k-1][j]+ (S[i]-s[j]) * (s[i]-S[j])) { -dp[k][i]=dp[k-1][j]+ (S[i]-s[j]) * (s[i]-s[j]); -p[k][i]=J; -                 } -             } -         } in     } -printf"%lld\n", 1ll*dp[m][n]*m-s[n]*S[n]);  to     return 0; +}

Dynamic Programming (decision Monotonic Optimization): Bzoj 4518 [Sdoi2016] Journey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.