728x90
반응형

알고리즘 133

[Baekjoon 13335 / Python / 실버1] 트럭

from collections import dequeimport sysinput = sys.stdin.readlineN, W, L = map(int, input().split())truck = list(map(int, input().split()))q = deque([0] * W) # 큐 사용time = 0 # 경과시간while q:    time += 1 # 반복할 때마다 시간 증가    q.popleft()    if truck:        if sum(q) + truck[0] L: # 무게 제한에 걸리지 않으면 다리에 올리기            q.append(truck.pop(0))        else:            q.append(0) # 무게에 걸렸다면, 다리길이를 맞추기 위해 0..

Algorithm/Queue 2024.08.16

[Baekjoon 15666 / Python / 실버2] N과 M (12)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()result = [-1] * Mdef compare(a, b):    if a > b:        return False    return Truedef backTracking(depth):    if depth == M:        print(' '.join(map(str, result)))        return        temp = 0    for i in range(N):        if temp != numbers[i] and (depth == 0 or compare(..

[Baekjoon 15665 / Python / 실버2] N과 M (11)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()result = [-1] * Mdef backTracking(depth):    if depth == M:        print(' '.join(map(str, result)))        return        temp = 0    for i in range(N):        if temp != numbers[i]:            temp = numbers[i]            result[depth] = numbers[i]            backTracking(d..

[Baekjoon 15664 / Python / 실버2] N과 M (10)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()visited = [False] * Nresult = [-1] * Mdef compare(a, b):    if a > b:        return False    return Truedef backTracking(depth):    if depth == M:        print(' '.join(map(str, result)))        return        temp = 0    for i in range(N):        if (depth == 0 and temp != n..

[Baekjoon 15663 / Python / 실버2] N과 M (9)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())visited = [False] * Nnumbers = list(map(int, input().split()))numbers.sort()result = [-1] * Mdef backTracking(depth):    if depth == M:        print(' '.join(map(str, result)))        return        # temp 변수를 활용하여 완성된 중복 순열을 방지한다.    temp = 0     for i in range(N):        if not visited[i] and temp != numbers[i]:            resu..

[Baekjoon 15657 / Python / 실버3] N과 M (8)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()box = []def compare(a, b):    if a > b:        return False    return Truedef backTracking(depth):        if depth == M:        print(' '.join(map(str, box)))        return        for i in range(N):        if depth == 0 or compare(box[depth-1], numbers[i]):            box.ap..

[Baekjoon 15656 / Python / 실버3] N과 M (7)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()box = []def backTracking(depth):    if depth == M:        print(' '.join(map(str, box)))        return        for i in range(N):        box.append(numbers[i])        backTracking(depth + 1)        box.pop()backTracking(0) 백트래킹( 사실 백트래킹도 아니다 )을 통해 모든 수열을 만들어 출력하기만 하면 된다. 중복 수..

[Baekjoon 15655 / Python / 실버3] N과 M (6)

import sysinput = sys.stdin.readline# 중복 없으며 뒷 숫자가 더 커야 한다N, M = map(int, input().split())numbers = list(map(int, input().split()))numbers.sort()box = []def compare(a, b):    if a >= b:        return False    return Truedef backTracking(depth):    if depth == M:        print(' '.join(map(str, box)))        return        for i in range(N):        if depth == 0 or (numbers[i] not in box and compar..

[Baekjoon 15654 / Python / 실버3] N과 M (5)

import sysinput = sys.stdin.readlineN, M = map(int, input().split())numList = list(map(int, input().split()))numList.sort()box = []def backTracking(depth):    if depth == M:        print(' '.join(map(str, box)))        return        for i in range(N):        if not numList[i] in box:            box.append(numList[i])            backTracking(depth + 1)            box.pop()backTracking(0) 앞선 N과 M ..

[Baekjoon 15652 / Python / 실버3] N과 M (4)

import sysinput = sys.stdin.readline# 1 ~ N 까지의 수, M자리N, M = map(int, input().split())def compare(a, b):    if a > b:        return False    return Truedef backTracking(depth, num):    if depth == M:        print(' '.join(num))        return        for i in range(1, N + 1):        if depth == 0 or compare(int(num[-1]), i):            backTracking(depth + 1, num + str(i))backTracking(0, '') 앞선 N과..

728x90
반응형