标签:des style blog java color strong
2 1 1 3
4
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; int dp[2050][2050]; int main() { int n,k,i,j,a[2050]; while(~scanf("%d%d",&n,&k)) { for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); memset(dp,0,sizeof(dp)); dp[2][1]=(a[2]-a[1])*(a[2]-a[1]); for(i=3;i<=n;i++) { for(j=1;j<=i/2;j++) { if(j*2==i) { dp[i][j]=dp[i-2][j-1]+(a[i]-a[i-1])*(a[i]-a[i-1]); } else { dp[i][j] = min(dp[i-1][j],dp[i-2][j-1]+(a[i]-a[i-1])*(a[i]-a[i-1])); } } } cout<<dp[n][k]<<endl; } return 0; }
标签:des style blog java color strong
原文地址:http://blog.csdn.net/fanerxiaoqinnian/article/details/28439811