标签:
10 1
1 1 2 3 3 3 4 6 10 20
5
//chopsticks弱化版 #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>>n>>m; for(int i = n;i >= 1;i--){ scanf("%d",&a[i]); } sort(a+1,a+1+n); m += 3; for(int i = 1;i <= m;i++){ for(int j = 1;j <= n;j++){ if(j < i * 2) 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] == 9876543212345L ? -1 : dp[m][n]); return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5791391.html