标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define mod 1000000007 #define pi (4*atan(1.0)) const int N=2e3+10,M=1e6+10,inf=1e9+10; int a[N]; int dp[N][N]; int main() { int x,y,z,i,t; while(~scanf("%d%d",&x,&y)) { for(i=0;i<=x;i++) for(t=0;t<=y;t++) dp[i][t]=inf; for(i=0;i<x;i++) for(t=0;t<=i/2;t++) dp[i][t]=0; for(i=1;i<=x;i++) scanf("%d",&a[i]); sort(a+1,a+x+1); dp[2][1]=(a[2]-a[1])*(a[2]-a[1]); for(i=3;i<=x;i++) for(t=1;2*t<=i&&t<=y;t++) dp[i][t]=min(dp[i-1][t],dp[i-2][t-1]+(a[i]-a[i-1])*(a[i]-a[i-1])); printf("%d\n",dp[x][y]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5601588.html