Before doing this problem you should first understand the triangle area formula: Helen formula .
Here conclusions to write a write, i.e., for three arbitrary sides of the triangle \ (A, B, C \) , so \ (X = \ tfrac {. 1} {2} (A + B + C) \) , then there is \ (S = \ sqrt {X (XA) (XB) (XC)} \) .
Next we consider the set state, so we \ (f [k] [a ] [b] [c] \) represents the former \ (K \) th wood whether surrounded three sides of length \ (a, b, c \) triangle. But the side length can be up to \ (800 \) , time and space complexity \ (800 ^ 3 \ Times 40 \) , it is clearly not feasible.
So we try to optimize, observed that the perimeter of the triangle is constant, then determine the two sides can find the third side. Set \ (C \) is the triangular perimeter, we make the \ (f [k] [a ] [b] \) represents the former \ (K \) th wood whether surrounded three sides of length \ (A, b, Cab \) triangle.
Transfer division three cases:
-
The section \ (K \) th wood on \ (I \) This sides:
Then prior to use \ (k-1 \) th boarded the sides at length \ (ia [k] \) and \ (J \) triangle, i.e. \ (f [k-1] [ia [k]] [j] \)
-
The section \ (K \) th wood on \ (J \) This sides: \ (F [. 1-K] [I] [JA [K]] \)
-
The section \ (K \) th wood on the third side: \ (F [. 1-K] [I] [J] \)
There are transfer equation:
At this point we continue to optimize space, easy to find and only when the transfer \ (f [k-1] [] [] \) related, so we get rid of the one-dimensional consider updating the current value of the array with the original data \ (f [ I] [J] \) .
It should be noted that \ (i, j \) should fall cycle, because we want to ensure that \ (f [i] [ja [k]] \) and \ (f [ja [k] ] [i] \) values are on the floor, and \ (01 \) backpack similar.
Finally, for \ (f [i] [j ] = 1 \) a \ (I, J \) , we determined \ ((i, j, Cij ) \) whether the composition triangle. If the composition is used to calculate the answer to Helen area update formula.
\(\operatorname{Code:}\)
#include<bits/stdc++.h>
using namespace std;
const int N=45;
int n,sum,ans=-1,a[N],f[805][805];
bool check(int x,int y,int z) {
if(x && y && z && x+y>z && y+z>x && x+z>y) return true;
return false;
}
int hailen(double x,double y,double z) {
double s=(x+y+z)/2;
return sqrt(s*(s-x)*(s-y)*(s-z))*100;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum=sum+a[i];
f[0][0]=1;
for(int k=1;k<=n;k++) {
for(int i=(sum>>1);i>=0;i--) {
for(int j=(sum>>1);j>=0;j--) {
if(i-a[k]>=0 && f[i-a[k]][j]) f[i][j]=1;
if(j-a[k]>=0 && f[i][j-a[k]]) f[i][j]=1;
}
}
}
for(int i=0;i<=(sum>>1);i++) {
for(int j=0;j<=(sum>>1);j++) {
if(f[i][j] && check(i,j,sum-i-j)) ans=max(ans,hailen(i,j,sum-i-j));
}
}
printf("%d\n",ans);
return 0;
}