当前位置:网站首页>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)
边栏推荐
- 建立高可用的数据库
- 数据批量写入
- Interpretation of OCP function of oceanbase Community Edition
- [simple] 155 Minimum stack
- DRF receives nested data and creates objects. Solution: DRF not NULL constraint failed
- Producer consumer model under multithreading model
- User guide for JUC concurrency Toolkit
- SQL tuning guide notes 15:controlling the use of optimizer statistics
- How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog
- 如何自己动手写一个vscode插件,实现插件自由!
猜你喜欢

Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?

SQL调优指南笔记9:Joins

Oracle livelabs experiment: introduction to Oracle Spatial

User guide for JUC concurrency Toolkit

SQL调优指南笔记8:Optimizer Access Paths

Turing prize winner: what should I pay attention to if I want to succeed in my academic career?

Ansible playbook and variable (II)

How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog

Cloning PDB with ADG standby

SQL tuning guide notes 10:optimizer statistics concepts
随机推荐
Can tonghuashun open an account? Is it safe to open an account in tonghuashun? How to open a securities account
[QNX hypervisor 2.2 user manual] 4.3 obtain the host component
SQL调优指南笔记6:Explaining and Displaying Execution Plans
大一下学年学期总结
SQL tuning guide notes 11:histograms
[qnx hypervisor 2.2 manuel de l'utilisateur] 4.2 environnement de construction pris en charge
Okio source code analysis
ICML2022 | GALAXY:極化圖主動學習
Oracle livelabs experiment: introduction to Oracle Spatial
[Jianzhi offer simple] Jianzhi offer 06 Print linked list from end to end
SQL tuning guide notes 16:managing historical optimizer statistics
How to develop programming learning with zero foundation during college
Economist focuses on WTO MC12: digital economy may become an important issue
Gzip compression decompression
Is it safe to open an account in tonghuashun? How to open an account
Zip compression decompression
Digraph deep copy
Linux backup MySQL
数据批量写入
JVisualVM初步使用