标签:des style class color get int
1题目:
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; #define M 999999999 int dp[2000][2000]; int getmin(int x, int y){ return x > y ? y : x; } int main(){ int n, k, i, j, a[2001], smax[2000], num; while(scanf("%d %d", &n, &k) != EOF){ num = 0; for(i = 1; i <= n; i ++){ scanf("%d", &a[i]); } sort(a, a + n + 1); //cout<<a[1]<<a[2]; for(i = 1; i < n; i ++){ smax[i] = (a[i] - a[i + 1]) * (a[i] - a[i + 1]); } for(i = 0; i <= n; i ++){ for(j = 0; j <= k; j ++){ dp[i][j] = M; } } for(i = 0; i <= n; i ++){ dp[i][0] = 0; } //核心代码 for(i = 2; i <= n; i ++){ for(j = 1; 2 * j <= i; j ++){ dp[i][j] = getmin(smax[i - 1] + dp[i - 2][j - 1], dp[i - 1][j]); } } cout << dp[n][k] << endl; } return 0; }
标签:des style class color get int
原文地址:http://www.cnblogs.com/xiaoyeye/p/3710536.html