#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 55;
int n, m;
double dp[maxn][maxn][maxn], p[maxn];
double fun(double x1, double x2)
{
return sin(min(x1 - x2, 1 - (x1 - x2)) * acos(-1.0)) * 2;
}
double Area(double a, double b, double c)
{
double A = fun(b, c), B = fun(a, c), C = fun(a, b);
double P = (A + B + C) / 2;
return sqrt(P * (P - A) * (P - B) * (P - C));
}
int main(int argc, char const *argv[])
{
while (~scanf("%d%d", &n, &m) && n + m)
{
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
scanf("%lf", &p[i]);
double ans = 0;
for (int i = 3; i <= m; i++)
for (int j = 1; j <= n; j++)
for (int k = j + 1; k <= n; k++)
for (int l = k + 1; l <= n; l++)
dp[j][l][i] = max(dp[j][l][i], dp[j][k][i - 1] + Area(p[j], p[k], p[l]));
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
ans = max(ans, dp[i][j][m]);
printf("%.6f\n", ans);
}
return 0;
}
第一反应是二维dp,但是并没有办法算图形面积,于是扩展为三维dp
dp[i][j][k]表示从第i个点到第j个点选k个点的最大面积 i,j必须选,
四重循环,k为多边形上最后第二个点,用海伦公式算出增量三角形的面积。