标签:
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 5 const int inf=0x3f3f3f3f; 6 int dp[2005][1005]; 7 int v[2005]; 8 9 int main() 10 { 11 int n,k,i,j; 12 dp[0][0]=0; 13 while(scanf("%d%d",&n,&k)!=EOF) 14 { 15 for(i=1;i<=n;i++) 16 scanf("%d",&v[i]); 17 for(i=0;i<=n;i++) 18 for(j=1;j<=k;j++) 19 dp[i][j]=inf; 20 sort(v,v+n+1); 21 for(i=2;i<=n;i++) 22 { 23 for(j=1;j*2<=i;j++) 24 dp[i][j]=min(dp[i-2][j-1]+(v[i]-v[i-1])*(v[i]-v[i-1]),dp[i-1][j]); 25 } 26 printf("%d\n",dp[n][k]); 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4744639.html