标签:
9 40
1 8 10 16 19 22 27 33 36 40 47 52 56 61 63 71 72 75 81 81 84 88 96 98 103 110 113 118 124 128 129 134 134 139 148 157 157 160 162 164
23
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; int m,n,a[5005]; long long dp[1005][5005]; int main(){ cin>>m>>n; for(int i = n;i >= 1;i--){ scanf("%d",&a[i]); } for(int i = 1;i <= m;i++){ for(int j = 1;j <= n;j++){ if(j < i * 3) dp[i][j] = 9876543212345L; else dp[i][j] = min(dp[i][j-1],dp[i-1][j-2] + (a[j] - a[j-1]) * (a[j] - a[j-1])); } } cout<<dp[m][n]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5754672.html