[GO] About bit full search that often appears in competition pros From the eyes of beginners with python

at first

I was a competition professional and started studying algorithms. I will explain the bit full search, which is the beginning of the algorithm, with the meaning of the output. I am still a young student, so please point out any mistakes. I will write in the main story of the competition professional.

What is bit full search?

This is one of the full search methods. This technique can be used when there are multiple variables and each variable takes two values. A bit is a computer that takes two values, 0 and 1. It is likened to. I think it's hard to understand from the explanation of the letters, so I'll put an example on it.

example

0,1 Only the two numbers of can be included in the list. The length of the list is 3. List all possible lists.

answer

bit.py


for i in range(2**3): #1
    list=[0]*3 #2
    for k in range(3): #3
        if ((i>>k)&1): #4
            list[k]=1 #5
    print(list)

Commentary

1 Each element in the list is 1 or 0, so the number of elements is 2 ** (the number of elements) 2 Create a temporary list. It will be rewritten later according to the result of bit operation. By the way, [0] * 3 = [0,0,0]. 3 The length of the list is 3, so you can shift it up to 2 times. 4 It is the core part of bit full search. i >> k means shift i to the left k times. Since & indicates and, this line means "i >> k means if i is shifted left k times and 1 is True".

Example in competition pro

https://atcoder.jp/contests/abc045/tasks/arc061_a

Important thing

Don't bring # 2 over the for loop

4 is the bit operator

& Is the logical product of bit operations, then | is the logical sum, ^ is the exclusive OR

Recommended Posts

About bit full search that often appears in competition pros From the eyes of beginners with python
Try to implement permutation full search that often appears in competition pros with python
Full bit search with Python
Solve with Python [100 selected past questions that beginners and intermediates should solve] (010 --014 Full search: Bit full search)
What beginners learned from the basics of variables in python
Solve the subset sum problem with a full search in Python
About the behavior of Model.get_or_create () of peewee in Python
Solve with Python [100 selected past questions that beginners and intermediates should solve] (015 --017 Full search: Permutation full search)
Get the value of a specific key in a list from the dictionary type in the list with Python
Learn Nim with Python (from the beginning of the year).
Find the part that is 575 from Wikipedia in Python
A reminder about the implementation of recommendations in Python
python bit full search
List of my articles that may be useful in competition pros (updated from time to time)
Try scraping the data of COVID-19 in Tokyo with Python
Calculate the square root of 2 in millions of digits with python
Tank game made with python About the behavior of tanks
[For beginners] Summary of standard input in Python (with explanation)
[Homology] Count the number of holes in data with Python
Google search for the last line of the file in Python
Create an application that just searches using the Google Custom Search API with Python 3.3.1 in Bottle
About the ease of Python
About the features of Python
The story of creating a bot that displays active members in a specific channel of slack with python
Solve with Python [100 selected past questions that beginners and intermediates should solve] (005 --- 009 All search: All enumeration to reduce the number of streets by devising)
Output the contents of ~ .xlsx in the folder to HTML with Python
A function that measures the processing time of a method in python
Read a file in Python with a relative path from the program
[Talking about the drawing structure of plotly] Dynamic visualization with plotly [python]
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
The story of making a module that skips mail with python
Workaround memo when Segmentation fault: 11 appears in import of opencv that was brew installed with virtualenv of python
[Completed version] Try to find out the number of residents in the town from the address list with Python
Analyze the source code of your own simple search engine written in Python with the code visualization tool "SOURCE TRAIL"
A story about creating a program that will increase the number of Instagram followers from 0 to 700 in a week
Learn search with Python # 2bit search, permutation search
Existence from the viewpoint of Python
About the basics list of Python basics
Learn the basics of Python ① Beginners
Results that did not get caught in the search with this word
Fill the string with zeros in python and count some characters from the string
[Python] Explore the characteristics of the titles of the top sites in Google search results
Solve with Python [100 past questions that beginners and intermediates should solve] (028 --033 breadth-first search)
Basic summary of scraping with Requests that beginners can absolutely understand [Python]
Extract lines that match the conditions from a text file with python
Receive a list of the results of parallel processing in Python with starmap
Features of regular expression modules that I often use personally in Python
Find out the name of the method that called it from the method that is python
From a book that makes the programmer's way of thinking interesting (Python)