当前位置:网站首页>Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
2022-06-12 21:54:00 【Review of the white speed Dragon King】
Ideas :
Less data
Binary representation of selection or No election , And then use delta Judge whether this method meets the requirements
Be careful all Usage of
src:
class Solution:
def maximumRequests(self, n: int, requests: List[List[int]]) -> int:
# Choose the most st Into the = Out of
# Multiple small closed loops
# Find out how many circles there are , And total points
# Forget it Look at the answer
# Ah, this , The answer is binary violence enumeration
ans = 0
for mask in range(1 << len(requests)):
cnt = mask.bit_count()
# Not bigger
if cnt <= ans:
continue
# It is used to record whether all are 0
delta = [0] * n
# See which one you chose
for j in range(len(requests)):
# This is not equal to 1, It's greater than 0!!!
if mask & (1 << j):
delta[requests[j][0]] -= 1
delta[requests[j][1]] += 1
# if delta All for 0, Description balance
if all(x == 0 for x in delta):
ans = cnt
return ans
summary :
Judge whether someone has chosen or not ==1, It is >0, Because it's someone on the , It should be 1000…
If you encounter small data, you can bf
Then by proper pruning (cnt <= ans break)
边栏推荐
- 孙老师版本JDBC(2022年6月12日21:34:25)
- PE installation win10 system
- June training (day 10) - bit operation
- 复杂系统如何检测异常?北卡UNCC等最新《复杂分布式系统中基于图的深度学习异常检测方法综述》,阐述最新图异常检测技术进展
- “Oracle数据库并行执行”技术白皮书读书笔记
- SQL tuning guide notes 15:controlling the use of optimizer statistics
- Thread safe level
- Oracle 19c 安装文档
- Unity 常用3D数学计算
- NIO使用指南
猜你喜欢
A puzzle about + =
Jin AI her power | impact tech, she can
PCB package download website recommendation and detailed usage
最近公共祖先问题你真的学会了吗?
Smart management of green agriculture: a visual platform for agricultural product scheduling
Ansible PlayBook et ansible roles (3)
How to write a vscode plug-in by yourself to realize plug-in freedom!
SQL调优指南笔记16:Managing Historical Optimizer Statistics
SQL调优指南笔记14:Managing Extended Statistics
Npoi create word
随机推荐
SQL调优指南笔记16:Managing Historical Optimizer Statistics
【QNX Hypervisor 2.2 用户手册】4.3 获取host组件
经济学人聚焦WTO MC12:数字经济或成重要议题
SQL tuning guide notes 15:controlling the use of optimizer statistics
Can tonghuashun open an account? Can the security of securities companies be directly opened on the app? How to open an account for securities accounts
[medium] 78 Subset (backtracking shall be supplemented later)
Economist focuses on WTO MC12: digital economy may become an important issue
SQL调优指南笔记18:Analyzing Statistics Using Optimizer Statistics Advisor
linux备份mysql
What is your understanding of thread priority?
[QNX hypervisor 2.2 user manual] 4.2 supported build environments
Yyds dry goods inventory solution sword finger offer: the first non repeated character in the character stream
[QNX hypervisor 2.2 user manual] 4.3 obtain the host component
Design and practice of Hudi bucket index in byte skipping
KDD2022 | GraphMAE:自监督掩码图自编码器
Oracle livelabs experiment: introduction to Oracle Spatial
ICML2022 | GALAXY:極化圖主動學習
February 27th
Ansible summary (VI)
Can tonghuashun open an account? Is it safe to open an account in tonghuashun? How to open a securities account