当前位置:网站首页>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)
边栏推荐
- Permission to query execution plan in Oracle Database
- [target detection] |dive detector into box for object detection new training method based on fcos
- 【QNX Hypervisor 2.2 用户手册】4.2 支持的构建环境
- [sword finger offer simple] sword finger offer 24 Reverse linked list
- SQL调优指南笔记15:Controlling the Use of Optimizer Statistics
- SQL tuning guide notes 8:optimizer access paths
- [medium] 78 Subset (backtracking shall be supplemented later)
- 同花顺能开户吗,在同花顺开户安全么,证券开户怎么开户流程
- 如何自己动手写一个vscode插件,实现插件自由!
- Exception encountered by selenium operation element
猜你喜欢

Ansible基础和常用模块(一)

Ansible PlayBook et ansible roles (3)

SQL tuning guide notes 13:gathering optimizer statistics

The ifeq, filter and strip of makefile are easy to use

多线程模型下的生产者消费者模式

Build a highly available database

Ansible playbook和Ansible Roles(三)

SQL tuning guide notes 11:histograms

ICML2022 | GALAXY:極化圖主動學習

SQL tuning guide notes 8:optimizer access paths
随机推荐
PE安装win10系统
gzip压缩解压缩
OceanBase 社区版 OCP 功能解读
Data batch writing
SQL调优指南笔记12:Configuring Options for Optimizer Statistics Gathering
[Jianzhi offer simple] Jianzhi offer 06 Print linked list from end to end
SQL tuning guide notes 9:joins
Ansible summary (VI)
selenium操作元素遇到的异常
linux备份mysql
六月集训(第11天) —— 矩阵
Vagrantbox reinstalling the vboxsf driver
经济学人聚焦WTO MC12:数字经济或成重要议题
Role of volatile keyword
lambda表达式与流优化代码
SQL tuning guide notes 17:importing and exporting optimizer statistics
SQL调优指南笔记14:Managing Extended Statistics
利用ADG Standby克隆PDB
MySQL introduction and installation (I)
建立高可用的数据库