当前位置:网站首页>956. Highest billboard pressure DP
956. Highest billboard pressure DP
2022-07-25 04:44:00 【Empress Yu】
956. The highest billboard
You're installing a billboard , And hope it's the highest . This billboard will have two steel supports , One on each side . The height of each steel support must be equal .
You have a bunch of steel bars that can be welded together
rods. for instance , If the length of the reinforcement is1、2and3, Then they can be welded together to form a length of6My bracket .return The maximum possible installation height of the billboard . If you can't install billboards , Please return
0.Example 1:
Input :[1,2,3,6] Output :6 explain : We have two disjoint subsets {1,2,3} and {6}, They have the same and sum = 6.Example 2:
Input :[1,2,3,4,5,6] Output :10 explain : We have two disjoint subsets {2,3,5} and {4,6}, They have the same and sum = 10.Example 3:
Input :[1,2] Output :0 explain : Can't install billboards , So back 0.Tips :
0 <= rods.length <= 201 <= rods[i] <= 1000sum(rods[i]) <= 5000
source : Power button (LeetCode)
link :https://leetcode.cn/problems/tallest-billboard
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The result of doing the question
success , But the effect is not good , Used shape pressure dp, The scope of this question is larger , The pressure cannot pass
Method : Pressure dp
1. Find the sum of all subsets
2. Take the subset of the inverse set of half subset , If the sum of the two is equal, add the answer
class Solution {
public int tallestBillboard(int[] rods) {
int ans = 0;
int n = rods.length;
int s = 0;
for (int rod : rods) {
s += rod;
}
int[] sums = new int[1 << n];
int mask = (1 << n);
for (int i = 1; i < mask; i++){
int last =Integer.bitCount( (i&(-i))-1);
int pre = i &(i-1);
sums[i]=sums[pre]+rods[last];
}
for(int i = 1; i < mask/2; i++){
int reverse = (i^(mask-1));
int sum = sums[i];
if(sum<=ans||sum>s/2||sums[reverse]<=ans)continue;
for(int j = reverse; j > 0; j = (reverse&(j-1))){
if(sum==sums[j]) {
ans = sum;break;
}
}
}
return ans;
}
}边栏推荐
- Ffmpeg download and installation
- 数据湖(十六):Structured Streaming实时写入Iceberg
- ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
- [cloud picture theory] 247 first introduction to Huawei cloud analysis service
- MySQL 中RDS 链接数突然上涨怎么查?
- In the process of data migration from Oracle to polardb for PostgreSQL, what does data migration mean?
- Interview required: how to design the seckill system?
- MongoDB的安全认证详解
- Summary of UPR optimization suggestions of unity
- Geely and Daimler set up a joint venture to produce pure electric smart in China!
猜你喜欢

Introduction to computing system hardware (common servers)

Zhongchuang computing power won the recognition of "2022 technology-based small and medium-sized enterprises"

Interviewer: explain the core principle of ThreadLocal

The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market

After watching the latest interview with big manufacturers, these six JVM interview questions were asked

Swagger simple quick start tutorial

Pyg builds GCN to realize link prediction

Token value replacement of burpsuite blasting
![[detailed tutorial] a thorough article on mongodb aggregation query](/img/81/1ac7afa778849b8a4b103107fd9cb6.png)
[detailed tutorial] a thorough article on mongodb aggregation query
![Introduction to fundamentals of operations research [1]](/img/79/b613bff74a78ad63f202b9e652220d.png)
Introduction to fundamentals of operations research [1]
随机推荐
Dry goods | Ctrip Hongmeng application development practice
TS learning (VII): interface and type compatibility of TS
Etcd learning
MongoDB的安全认证详解
Interview required: how to design the seckill system?
LVGL 8.2 Message box
[cloud picture theory] 248 illustrated public network domain name resolution: easy domain name access to websites / mailboxes
6.7 billion dollars! The acquisition of IDT by Renesas Electronics was finally approved!
二、MySQL数据库基础
Geely and Daimler set up a joint venture to produce pure electric smart in China!
LVGL 8.2 Spinbox
Construction of Seata multilingual system
Thinking from the perspective of Aya
Function and technical principle of data desensitization [detailed explanation]
What causes the wait event of TCP socket (kgas) in oracle?
etcd学习
[golang from introduction to practice] poker licensing game
MySQL -- index and transaction isolation level
Dig deep into data dividends, Intel and industry accelerate the implementation of digital economy
[sht30 temperature and humidity display based on STM32F103]