当前位置:网站首页>Triangle ranch (0/1 backpack)
Triangle ranch (0/1 backpack)
2022-07-19 06:06:00 【lovesickman】
Triangle ranch
Title Description
Like everyone , Cows love change . They are imagining new pastures . Dairy architects Hei Want to build a triangular ranch with beautiful white fences . She has n n n A board , The length of each piece l i l_i li Are integers. , She wanted to form a triangle with all the boards to make the pasture the largest .
Please help Hei Miss, build such a pasture , And calculate the area of the largest pasture .
Input format
The first 1 1 1 That's ok : An integer n n n;
The first 2 2 2 To the first ( n + 1 ) (n + 1) (n+1) That's ok , One integer per row , The first ( i + 1 ) (i + 1) (i+1) The whole number of lines l i l_i li It means the first one i i i The length of the board .
Output format
Only one integer : Multiply the maximum pasture area by 100 100 100 Then the ending result . If you can't build , Output − 1 -1 −1.
Examples #1
The sample input #1
5
1
1
3
3
4
Sample output #1
692
Tips
Sample input and output 1 explain
692 = Left behind ( 100 × Triangle area ) 692=\text{ Left behind }(100\times\text{ Triangle area }) 692= Left behind (100× Triangle area ), This triangle is an equilateral triangle , Side length is 4 4 4.
Data scale and agreement
about 100 % 100\% 100% The data of , Guarantee 3 ≤ n ≤ 40 3\le n\le40 3≤n≤40, 1 ≤ l i ≤ 40 1\le l_i\le40 1≤li≤40.
obvious d f s dfs dfs The time complexity of is O ( 3 40 ) O(3^{40}) O(340)
void dfs(int u,int A,int B,int C){
if(u>n){
if(A+B>C && A+C>B && B+C>A){
double p = (A+B+C)/2;
double s = sqrt(p*(p-A)*(p-B)*(p-C));
ans = max(ans, (ll)(s*100));
}
return ;
}
dfs(u+1,A+a[u],B,C);
dfs(u+1,A,B+a[u],C);
dfs(u+1,A,B,C+a[u]);
}
Easy to think of f [ i ] [ j ] [ k ] f[i][j][k] f[i][j][k] Before use i i i A stick , The first 1 The side length of the strip is j j j, The first 2 The side length of the strip is k k k Can the triangle of form .40 * 800 * 800 It is acceptable .
I encountered a big hole when I was writing , Some strange , There is no judgment 3 Border relations also A 了 , Is it data water ?
Of course, this question can be changed 2 dimension .
/* A: 10min B: 20min C: 30min D: 40min */
#include <iostream>
#include <stack>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mem(f, x) memset(f,x,sizeof(f))
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo_(i,a,n) for(int i=(a);i<(n);++i)
#define debug(x) cout<<#x<<":"<<x<<endl;
#define endl '\n'
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template<typename T>
ostream& operator<<(ostream& os,const vector<T>&v){
for(int i=0,j=0;i<v.size();i++,j++)if(j>=5){
j=0;puts("");}else os<<v[i]<<" ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>&v){
for(auto c:v)os<<c<<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>&v){
for(auto c:v)os<<c.first<<" "<<c.second<<endl;return os;}
template<typename T>inline void rd(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {
if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
typedef pair<int,int>PII;
typedef pair<long,long>PLL;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+10;
int n,m,_;
int a[50],f[50][810][810];
double ans,sum;
double area(double a,double b){
double c = sum-a-b;
double p = (a+b+c)/2;
double s = sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
void solve(){
cin>>n;
fo(i,1,n){
cin>>a[i];
sum+=a[i];
}
f[0][0][0]=1;
for(int i=1;i<=n;i++){
for(int j=sum/2;j>=0;j--){
for(int k=sum/2;k>=0;k--){
f[i][j][k] |= f[i-1][j][k];
if(j-a[i]>=0){
f[i][j][k] |= f[i-1][j-a[i]][k];
}
if(k-a[i]>=0){
f[i][j][k] |= f[i-1][j][k-a[i]];
}
}
}
}
ans = -1;
for(int k=1;k<=n;k++){
for(int i=sum/2;i>0;i--)
for(int j=sum/2;j>0;j--)
{
if(!f[k][i][j]) continue;
ans=max(ans,area(i,j));// Update answers
}
}
if(ans!=-1){
cout<<(ll)(ans*100)<<endl;
}
else
cout<<ans<<endl;
}
int main(){
solve();
return 0;
}
边栏推荐
- minio基础知识介绍
- 软考初、中、高级考试全体验
- Ht7727 ht7730 ht7733 ht7737 ht7750 asynchronous DCDC boost IC
- busybox 指定日期修改 暂时不需要clock -w 写入硬件
- Fs5383a lithium battery 3.7V input power supply solar lawn lamp drive IC
- 配置VsCode中‘log’快捷键去掉console.log(‘‘);中的分号;
- MCU single chip OTP
- Go language introduction and application scenario analysis
- 2021-09-15
- golang 多项目工作区搭建
猜你喜欢

Golang multi project workspace construction

minio安装部署及简单使用

2022/07/11 第五小组 丁帅 学习笔记 day04

Tips for using tp4054 charging IC -- used in conjunction with Zhongke Lanxun ab5365b

2022/07/12 学习笔记 (day05)循环

[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....

2022/07/09 第五小组 丁帅 学习笔记 day02

數學基礎課2_歐拉函數,線性篩,擴歐

WebService接口的创建与实现

RestClient查询文档
随机推荐
【力扣】相同的树
Conversion, isolation and transmission of international standard signals 0-5v/0-10v/1-5v, 0-10ma/0-20ma/4-20ma, etc
获取当前年月日、时分秒、星期,并实时更新
Qt Creator闪退解决办法
嵌入式C语言volatile作用
配置VsCode中‘log’快捷键去掉console.log(‘‘);中的分号;
4-channel encoder pulse counter, 8-Channel do, Modbus TCP module
High voltage module isolation module hra2460d-2w
XOR-gun (位运算,思维,区间暴力)
2022/07/12 学习笔记 (day05)JS内置函数
mapping索引属性 & 创建索的操作
软考初、中、高级考试全体验
谷歌浏览器不能手动修改cookies,cookie报红标红
RS-485/232转4-20mA/0-10V隔离D/A转换器
Vscode configuring golang development environment
Wide voltage input high voltage output voltage control type
QTSS常数
busybox 指定日期修改 暂时不需要clock -w 写入硬件
Complete scheme diagram of lth7 five pin chip fs4054 charging circuit principle
vscode 配置golang开发环境