POJ1948 Triangular Pastures
#include <iostream>
#include <cmath>
using namespace std;
const int maxn = ;
bool dp[maxn][maxn];
int a[maxn];
double area(double a, double b, double c) {
double p = (a+b+c)/;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
bool is_ok(int a, int b, int c) {
if (a+b <= c || a+c <= b || b+c <= a)
return false;
return true;
}
int main() {
int n; cin >> n;
int sum = ;
for (int i = ; i < n; i++) {
cin >> a[i];
sum += a[i];
}
dp[][] = true;
for (int i = ; i < n; i++) {
for (int k = ; k >= ; k--) {
for (int j = k; j >= ; j--) {
if (k-a[i] >= && dp[k-a[i]][j])
dp[k][j] = true;
if (j-a[i] >= && dp[k][j-a[i]])
dp[k][j] = true;
}
}
}
double ans = ;
for (int i = ; i <= ; i++) {
for (int j = ; j <= i; j++) {
if (dp[i][j] && is_ok(i,j,sum-i-j))
ans = max(ans,*area(i,j,sum-i-j));
}
}
if (ans == ) cout << - << endl;
else cout << (int)ans << endl;
return ;
}