标签:des style color io os ar for sp div
2 3 1.5 2.0 1.5 1.7 2.0 0 0
0.000000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<cmath>
typedef long long LL;
using namespace std;
const int maxn=10000+100;
double A[maxn],G[maxn];
double dp[2][maxn];
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m)&&(n+m))
{
if(n>m) swap(n,m);
for(int i=1;i<=n;i++)
scanf("%lf",&A[i]);
for(int i=1;i<=m;i++)
scanf("%lf",&G[i]);
double *b=A,*g=G;
// if(n>m) {swap(n,m);swap(b,g);}
memset(dp,0,sizeof(dp));
sort(b+1,b+n+1);
sort(g+1,g+m+1);
for(int i=1;i<=n;i++)
{
for(int j=i;j<=i+m-n;j++)
{
if(i==j)
dp[i&1][j]=dp[(i-1)&1][j-1]+fabs(b[i]-g[j]);
else
dp[i&1][j]=min(dp[(i-1)&1][j-1]+fabs(b[i]-g[j]),dp[i&1][j-1]);
}
}
printf("%.6f\n",dp[n&1][m]);
}
return 0;
}
/*
2 5
1.0 2.0
0.7 1.5 1.5 1.8 2.8
5 2
0.7 1.5 1.5 1.8 2.8
1.0 2.0
*/
标签:des style color io os ar for sp div
原文地址:http://blog.csdn.net/u013582254/article/details/39852679