[Python] Search (itertools) ABC167C

ABC167C

Search using itertools In many cases, full bit search is recommended for search, but I think that it is more practical to use itertools for Python. Summary of all enumerations that can be done with itertools in Python

Sample code


import itertools

N, M, X = list(map(int, input().split()))
a = [list( map( int, input().split() ) ) for i in range(N)]

for x in itertools.product([0,1], repeat=2):
  cost = 0
  level = [] * M
  judge = True
  ans = 1234567
  for i in range(N):
    if a[i] == 1:
      cost += a[i][0]
      level = [y + z for (y, z) in zip(level, a[i][1:])]
  for j in range(M):
    if any(level[k] < x for k in range(M)):
      judge = False
  if judge:
    ans = min(ans, cost)

if ans == 1234567:
  print(-1)
else:
  print(ans)

Recommended Posts

[Python] Search (itertools) ABC167C
[Python] Search (NumPy) ABC165C
[Python] BFS (breadth-first search) ABC007C
ABC146C (binary search)
Sequential search with Python
Python Exercise 1-Breadth-first search
Solve ABC146-C in Python
Binary search in Python
Binary search (python2.7) memo
[Python] Binary search ABC155D
Solve ABC098-C in Python
python bit full search
Linear search in Python
Binary search with python
Binary search with Python3
Search Twitter using Python
Binary search in Python (binary search)
[Python] BFS (breadth-first search) ABC168D
Search for strings in Python
Breadth-first search / bidirectional search (Python version)
Search algorithm using word2vec [python]
Homebrew Python --Youtube Search Program
[Python] DFS (Depth-first Search) ATC001A
Binary search in Python / C ++
Algorithm in Python (binary search)
Full bit search with Python
[Python] DFS (Depth-first Search) ABC157D
[AtCoder] ABC165C Personal Note [Python]
Search engine work with python
Search twitter tweets with python
[Python] Depth-first search and breadth-first search
Streamline web search with python
Write a binary search in Python
Python
Learn search with Python # 2bit search, permutation search
Breadth-first search (BPF) Maybe understood (python)
Algorithm in Python (depth-first search, dfs)
Master linear search! ~ Python implementation version ~
Write a depth-first search in Python
[At Coder] ABC085C --Otoshidama's Python answer
# 2 Python beginners challenge AtCoder! ABC085C --Otoshidama
Reproduce One-Touch Search on Python 3.7.3. (Windows 10)
Depth-first search using stack in Python
Python Computation Library Cheat Sheet ~ itertools ~
Python 2-minute search and its derivation
Algorithm learned with Python 10th: Binary search
Homebrew Python Part 3-Amazon Product Search Program
Algorithm in Python (ABC 146 C Binary Search
Search and play YouTube videos in Python
Search the maze with the python A * algorithm
In search of the fastest FizzBuzz in Python
Homebrew search from python module name (ShellScript)
Algorithm learned with Python 12th: Maze search