zoukankan      html  css  js  c++  java
  • HDU5135 I

    首先开头膜一发ZB大爷,14广州竟然俩一血,另个一血太难,可能是模拟?反正之后在补吧。

    状压DP,网上说贪心也对,但是按照ZB大爷手速,十一分钟写一个不快。

    上代码1A

     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <cmath>
     5 #include <cstdio>
     6 using namespace std;
     7 double halen(int x,int y,int z)
     8 {
     9     double p = (x+y+z)/2.0;
    10     return sqrt(p*(p-x)*(p-z)*(p-y));
    11 }
    12 int a[20];
    13 double dp[1<<13];
    14 int vis[1<<13];
    15 int N;
    16 double dfs(int t)
    17 {
    18     if (vis[t]) return dp[t];
    19     for (int i = 0 ; i<N; i++) if ((t>>i)&1)
    20         for (int j = i+1; j<N; j++) if ((t>>j)&1)
    21           for (int k = j+1; k<N;k++)  if ((t>>k)&1)
    22           {
    23               if (a[i]+a[j] > a[k])
    24                  dp[t] = max(dp[t],dfs(t-(1<<i)-(1<<j)-(1<<k))+ halen(a[i],a[j],a[k]) );
    25           }
    26     vis[t] = 1;
    27     return dp[t];
    28 }
    29 int main()
    30 {
    31 
    32     while (cin >> N&&N)
    33     {
    34         for (int i = 0; i<N; i++)
    35         {
    36             cin >> a[i];
    37         }
    38         sort(a,a+N);
    39         memset(vis,0,sizeof(vis));
    40         memset(dp,0,sizeof(dp));
    41         dfs((1<<(N+1))-1);
    42         printf("%.2f
    ",dp[(1<<(N+1))-1]);
    43     }
    44 }
  • 相关阅读:
    [状压DP][二分]JZOJ 3521 道路覆盖
    字符串操作
    练习: 判断一个数是否为小数
    Python 深浅拷贝
    编码
    python中的 == 和 is 的区别
    Python3 字典的增删改查
    Python3 列表的基本操作
    初识 Python
    方法的入门
  • 原文地址:https://www.cnblogs.com/HITLJR/p/6602895.html
Copyright © 2011-2022 走看看