Problem Description
3 1 1 20 7 3 4 5 3 4 5 90 0
0.00 13.64
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; int const MAX = (1 << 13); int ok[MAX], a[105]; double re[MAX], dp[MAX]; bool judge(int a, int b, int c) { if(a + b > c && a + c > b && b + c > a) return true; return false; } double area(int a, int b, int c) { double p = (a + b + c) / 2.0; return sqrt(p * (p - a) * (p - b) * (p - c)); } int main() { int n; while(scanf("%d", &n) != EOF && n) { int cnt = 0; bool flag = false; memset(dp, 0, sizeof(dp)); memset(re, 0, sizeof(re)); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) for(int k = j + 1; k < n; k++) if(judge(a[i], a[j], a[k])) { flag = true; ok[cnt] = ((1 << i) | (1 << j) | (1 << k)); re[cnt++] = area(a[i], a[j], a[k]); } if(!flag) { printf("0.00\n"); continue; } for(int i = 0; i <= MAX; i++) for(int j = 0; j < cnt; j++) if(!(i & ok[j])) dp[(i | ok[j])] = dp[i] + re[j]; double ans = 0.0; for(int i = 0; i <= MAX; i++) ans = max(ans, dp[i]); printf("%.2f\n", ans); } }
HDU 5135 Little Zu Chongzhi's Triangles (14广州 状压dp)
原文地址:http://blog.csdn.net/tc_to_top/article/details/44003357