标签:des style blog http color os io strong
Description
Input
Output
Sample Input
Sample Output
dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+(a[i-1]-a[i])*(a[i-1]-a[i]));
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int MAXN=2020; 6 int dp[MAXN][MAXN/2]; 7 int a[MAXN]; 8 int main() 9 { 10 int n,k; 11 while(scanf("%d%d",&n,&k)!=EOF) 12 { 13 for(int i=1; i<=n; i++) 14 scanf("%d",&a[i]); 15 sort(a+1,a+n+1); 16 int max1=100000000;//不要超int,只要8位就行 17 for(int i=0; i<=n; i++) 18 for(int j=1; j<=k; j++) 19 dp[i][j]=max1; 20 for(int i=0; i<=n; i++) 21 dp[i][0]=0; 22 for(int i=2; i<=n; i++) 23 for(int j=1; 2*j<=i; j++) 24 { 25 dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+(a[i-1]-a[i])*(a[i-1]-a[i])); 26 } 27 printf("%d\n",dp[n][k]); 28 } 29 return 0; 30 }
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/angledamon/p/3899059.html