I am writing an article as an output because I learned the permutation full search while learning the algorithm. I am still a young student, so please point out any mistakes.
This is a full search method that enumerates all the lists in which the elements are rearranged for a list containing different elements. For example, if you search [1,2,3] in a permutation, [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1] , 2], [3,2,1] get 6 permutations.
permutations.rb
from itertools import permutations
list=[1,2,3]
per=permutations(list,2)
for i in per:
print(i)
ans.py
(1, 2)
(1, 3)
(2, 1)
(2, 3)
(3, 1)
(3, 2)
-Generate permutations using the library itertools.permutations. -Since permutations is an iterator, it cannot be output as it is. For example, the above code does not print as print (per) -By specifying a number in the second argument of permutations, you can generate a permutation that includes that number.
https://atcoder.jp/contests/abc150/tasks/abc150_c
This is a good question for beginners who can understand permutation full search. Let's also learn how to use the index function here
Recommended Posts