백준 1107번(리모컨)

ansehun·2022년 9월 5일
0

백준 코딩 연습

목록 보기
3/9

📒 알고 가야 하는 것

- 브루트-포드 알고리즘: 모든 자료를 탐색하여 원하는 정보를 얻음.
- 중복 순열: 중복하여 나타날 수 있는 모든 경우

📌 코드

import sys

N = int(sys.stdin.readline())
M = int(sys.stdin.readline())
if M != 0 :
    x = list(map(int, sys.stdin.readline().rstrip().split()))
else :
    x = []
new = []
for i in range(0,10,1) :
    if i not in x :
        new.append(str(i))

def product(arr,r):
    for i in range(len(arr)):
        if r == 1:
            yield arr[i]
        else:
            for next in product(arr,r-1):
                yield arr[i] + next

tmp = []
for i in range(1, 7) :
    for pro in product(new, i) :
        tmp.append(int(pro))  

minmin = abs(N-100)
x = []
for i in tmp :
    count = len(str(i)) + abs(N-i)
    x.append([i, count])
    if minmin > count :
        minmin = count
print(minmin)


### 📌 **피드백**
  • 브루스포트 알고리즘이라고 하지만 사실상 모든 경우를 탐색하는 것
  • 꽤 오랜 시간이 걸렸지만 한 번에 성공했다!
  • 포기하지 않고 도전하는 자세가 중요하다는 것을 깨달음
  • 중복 순열, 조합 등등에 대해서 구현하는 방식에 대해서 공부할 필요가 있음.

0개의 댓글