1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> using namespace std;
inline int f(int a,int b,int c){ double p = (a +b+c)/2.0; return (int)(100.0*sqrt(p*(p-a)*(p-b)*(p-c))); }
inline bool check(int a,int b,int c){ if (a + b > c && a + c > b && b + c > a) return true; else return false; } int ans = 0; int n,num[45],to[45]; void dfs(int id,int a,int b,int c){ if (id == n) { if (check(a,b,c)) { ans = max(ans,f(a,b,c)); } return; } if (a + to[n - 1] - to[id] + b + num[id] < c) return; if (a + to[n - 1] - to[id] + c + num[id] < b) return; if (c + to[n - 1] - to[id] + b + num[id] < a) return; if (a > to[n - 1] / 2) return; if (b > to[n - 1] / 2) return; if (c > to[n - 1] / 2) return; dfs(id + 1,num[id] + a, b, c); dfs(id + 1,a, num[id] + b, c); dfs(id + 1,a, b, num[id] + c); }
int dp[2][1655][1655]; int main() { while (~scanf("%d",&n) && n){ ans = -1; for (int i = 1; i <= n; i ++){ scanf("%d", &num[i]); if (i == 0) to[0] = num[0]; else to[i] = to[i - 1] + num[i]; } sort(num,num + n);
memset(dp,-1,sizeof(dp)); dp[0][0][0] = 0; for (int i = 1; i <= n; i ++){ for (int j = 0; j <= to[i]; j ++){ for (int k = 0; k <= to[i]; k ++){ if (j - num[i] >= 0){ if (dp[(i + 1) % 2][j - num[i]][k] != -1){ if (check(j,k,to[i] - j - k)) dp[i % 2][j][k] = max(dp[i % 2][j][k],f(j,k,to[i]-j-k)); else dp[i % 2][j][k] = max(0,dp[i % 2][j][k]); } } if (k - num[i] >= 0){ if (dp[(i + 1) % 2][j][k - num[i]] != -1){ if (check(j,k,to[i] - j - k)) dp[i % 2][j][k] = max(dp[i % 2][j][k],f(j,k,to[i]-j-k)); else dp[i % 2][j][k] = max(0,dp[i % 2][j][k]); } } if (to[i] - j - k - num[i] >= 0){ if (dp[(i + 1) % 2][j][k] != -1){ if (check(j,k,to[i] - j - k)) dp[i % 2][j][k] = max(dp[i % 2][j][k],f(j,k,to[i]-j-k)); else dp[i % 2][j][k] = max(0,dp[i % 2][j][k]); } } } } } for (int i = 0; i <= to[n]; i ++) for (int j = 0; j <= to[n]; j ++){ ans = max(dp[n % 2][i][j],ans); } printf("%dn", ans == 0? -1:ans ); } return 0; }
|