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 ;
}

POJ1948 Triangular Pastures的更多相关文章

  1. Triangular Pastures POJ - 1948

    Triangular Pastures POJ - 1948 sum表示木条的总长.a[i]表示第i根木条长度.ans[i][j][k]表示用前i条木条,摆成两条长度分别为j和k的边是否可能. 那么a ...

  2. poj 1948 Triangular Pastures 小结

    Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The o ...

  3. Triangular Pastures (二维01背包)

    描述Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectang ...

  4. POJ 1948 Triangular Pastures【二维01背包】

    题意:给出n条边,用这n条边构成一个三角形,求三角形的最大面积. 先求面积,用海伦公式,s=sqrt(p*(p-a)*(p-b)*(p-c)),其中a,b,c分别为三角形的三条边,p为三角形的半周长, ...

  5. [POJ] 1948 Triangular Pastures (DP)

    题目地址:http://poj.org/problem?id=1948 题目大意: 给N条边,把这些边组成一个三角形,问面积最大是多少?必须把所有边都用上. 解题思路: 根据题意周长c已知,求组合三边 ...

  6. POJ 1948 Triangular Pastures

    题意: 把很多单独的线段重新组合成一个三角形,使得三角形面积最大(所有的线段都必须用上). 思路: 三角形的任意一条边的边长不能超过周长的一半,只需要用dp枚举两条边j,k,剩下的一条边长为tot  ...

  7. poj 01背包

    首先我是按这篇文章来确定题目的. poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<algo ...

  8. POJ之01背包系列

    poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<iostream> using na ...

  9. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

随机推荐

  1. GitHub 如何忽略文件或者文件夹

    在我们开发项目的时候,往往会产生一些不必要的文件,我们会选择忽略他们,不提交到版本控制中,那我们该如何做呢? 步骤一:在项目根目录下,右键,git bash,在弹出的命令行输入框中输入命令:touch ...

  2. Mac home 目录下创建文件夹

    example:sudo vim /etc/auto_master before: # Automounter master map +auto_master # Use directory serv ...

  3. Babel 在浏览器环境使用方法

    Babel 也可以用于浏览器环境.但是,从 Babel 6.0 开始,不再直接提供浏览器版本,而是要用构建工具构建出来.如果你没有或不想使用构建工具 1.通过安装5.x版本的babel-core模块获 ...

  4. Codeforce-CodeCraft-20 (Div. 2)-C. Primitive Primes(本原多项式+数学推导)

    It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gav ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

    A After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the ...

  6. python(re 模块)

    1.re.match() 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回none. group() 以str形式返回对象中match的元素 start() 返回 ...

  7. 最新Idea超实用告别996插件,都是免费

    Idea告别996插件 在IntelliJ IDEA中,秉着IDEA自带能实现的快捷方式就不用插件的原则,少用些插件,运行性能也提升一些,虽然很少,哈哈.分享下我个人常用的插件,希望对大家有些帮助.插 ...

  8. C++11的mutex和lock_guard,muduo的MutexLock 与MutexLockGuard

    互斥锁是用来保护一段临界区的,它可以保证某段时间内只有一个线程在执行一段代码或者访问某个资源. C++11的mutex和lock_guard C++11新增了mutex,使用方法和linux底下的常用 ...

  9. 集训模拟赛-1-T1

    最近学校网课跟得紧没时间写知识点,就拿题解凑个数(bushi 而且前两天我打着打着题解电脑就突然死机 幸运的是 我没有保存(微笑) 废话不多说 上题目! 城市攻击 (city) (256MB,1s) ...

  10. POJ2376Cleaning Shifts(区间覆盖贪心)

    应该还是蛮简单的一题,但是因为模拟太差,一直没调出来....... \(显而易见的应该按照左区间从小到大排序,相等按照右区间大到小排序\). \(那么第一个区间的l一定要是1,而且必拿(否则没有区间能 ...