Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<algorithm>
- using namespace std;
- int a[3030];
- typedef long long l;
- l dp[3030];
- int main()
- {
- int n,c;
- scanf("%d%d",&n,&c);
- for(int i=1;i<=n;i++) scanf("%d",&a[i]);
- for(int i=1;i<=n;i++){
- dp[i]=1e18;
- for(int j=1;j<=i;j++){
- l walk=(l)(a[i]-a[j])*(l)(a[i]-a[j]);
- dp[i]=min(dp[i],walk+(l)c+dp[j-1]);
- }
- }
- printf("%lld",dp[n]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement