Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<algorithm>
  3. using namespace std;
  4. int a[3030];
  5. typedef long long l;
  6. l dp[3030];
  7. int main()
  8. {
  9.   int n,c;
  10.   scanf("%d%d",&n,&c);
  11.   for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  12.   for(int i=1;i<=n;i++){
  13.     dp[i]=1e18;
  14.     for(int j=1;j<=i;j++){
  15.       l walk=(l)(a[i]-a[j])*(l)(a[i]-a[j]);
  16.       dp[i]=min(dp[i],walk+(l)c+dp[j-1]);
  17.     }
  18.   }
  19.   printf("%lld",dp[n]);
  20.   return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement