标签:ios des 选择 ott return nbsp 时间 状态 input
#include <cstdio> #include <map> #include <iostream> #include<cstring> #include<bits/stdc++.h> #define ll long long int #define M 6 using namespace std; inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int dir[4][2]={1,0 ,0,1 ,-1,0 ,0,-1}; int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1}; const int inf=0x3f3f3f3f; const ll mod=1e9+7; int n,k; int a[2007]; int dp[2007][2007]; //表示前i个物品中选择了j对 int main(){ ios::sync_with_stdio(false); while(cin>>n>>k){ for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n); //保证相差最小 for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) dp[i][j]=inf; dp[0][0]=0; for(int i=2;i<=n;i++) for(int j=1;2*j<=i;j++){ 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; }
标签:ios des 选择 ott return nbsp 时间 状态 input
原文地址:https://www.cnblogs.com/wmj6/p/10392341.html