当前位置:网站首页>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)
边栏推荐
- SQL tuning guide notes 18:analyzing statistics using optimizer statistics Advisor
- About the solution to "the application cannot start normally 0xc00000022" after qt5.15.2 is installed and qtcreator is started
- Permission to query execution plan in Oracle Database
- SQL tuning guide notes 17:importing and exporting optimizer statistics
- Oracle LiveLabs实验:Introduction to Oracle Spatial
- How to develop programming learning with zero foundation during college
- Turing prize winner: what should I pay attention to if I want to succeed in my academic career?
- Oracle SQL Developer的代码输入框中推荐使用的中文字体
- lambda表达式与流优化代码
- February 27th
猜你喜欢

Kdd2022 | graphmae: self supervised mask map self encoder

MySql主从复制

JUC并发工具包使用指南

CVPR 2022 | 应对噪声标签,西安大略大学、字节跳动等提出对比正则化方法

SQL调优指南笔记10:Optimizer Statistics Concepts

SQL tuning guide notes 16:managing historical optimizer statistics

Ansible foundation and common modules (I)

SQL tuning guide notes 18:analyzing statistics using optimizer statistics Advisor

最近公共祖先问题你真的学会了吗?

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
随机推荐
Npoi create word
Okio source code analysis
SQL tuning guide notes 17:importing and exporting optimizer statistics
Can tonghuashun open an account? Is it safe to open an account in tonghuashun? How to open a securities account
DRF receives nested data and creates objects. Solution: DRF not NULL constraint failed
Ansible summary (VI)
在同花顺开户证券安全吗,证券开户怎么开户流程
Libmysqlclient A static library
[simple] 155 Minimum stack
MySQL architecture and basic management (II)
SQL tuning guide notes 10:optimizer statistics concepts
Exception encountered by selenium operation element
What is the difference between volatile variables and atomic variables?
SQL tuning guide notes 13:gathering optimizer statistics
PCB封装下载网站推荐及其详细使用方法
Role of volatile keyword
Open source background management system suitable for outsourcing projects
MySQL introduction and installation (I)
Simple understanding of cap and base theory
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