본문 바로가기

Problem Solving/BOJ60

[Meet in the Middle] python 1450 냅색문제 https://www.acmicpc.net/problem/1450 1450번: 냅색문제 첫째 줄에 N과 C가 주어진다. N은 30보다 작거나 같은 자연수, C는 109보다 작거나 같은 음이 아닌 정수이다. 둘째 줄에 물건의 무게가 주어진다. 무게도 109보다 작거나 같은 자연수이다. www.acmicpc.net # 2023.01.19 import sys input = sys.stdin.readline n, c = map(int, input().split()) # 물건, 최대 무게 item = list(map(int, input().split())) item1 = item[:n//2] item2 = item[n//2:] sum1=[] sum2=[] def bruteforce(item, sum, index,.. 2023. 1. 20.
[DFS] 1987 알파벳 https://www.acmicpc.net/problem/1987 1987번: 알파벳 세로 R칸, 가로 C칸으로 된 표 모양의 보드가 있다. 보드의 각 칸에는 대문자 알파벳이 하나씩 적혀 있고, 좌측 상단 칸 (1행 1열) 에는 말이 놓여 있다. 말은 상하좌우로 인접한 네 칸 중의 한 칸으 www.acmicpc.net # 2023.01.18 import sys input = sys.stdin.readline r, c = map(int, input().split()) alpha = [list(input().rstrip()) for _ in range(r)] visited=[0]*(26) # 26개의 알파벳을 방문했는지 check visited[ord(alpha[0][0])-65]=1 # 0행 0열의 알파벳.. 2023. 1. 18.
[Combination] 16938 캠프 준비 https://www.acmicpc.net/problem/16938 16938번: 캠프 준비 난이도가 10, 30인 문제를 고르거나, 20, 30인 문제를 고르면 된다. www.acmicpc.net # 2023.01.18 # 조합 import sys input = sys.stdin.readline from itertools import combinations n, l, r, x = map(int, input().split()) problem = list(map(int, input().split())) answer=0 for i in range(2, n+1): # 2~n개의 수를 선택 가능 for subProb in combinations(problem, i): if l 2023. 1. 18.
[BOJ] 16928 뱀과 사다리 게임 https://www.acmicpc.net/problem/16928 16928번: 뱀과 사다리 게임 첫째 줄에 게임판에 있는 사다리의 수 N(1 ≤ N ≤ 15)과 뱀의 수 M(1 ≤ M ≤ 15)이 주어진다. 둘째 줄부터 N개의 줄에는 사다리의 정보를 의미하는 x, y (x < y)가 주어진다. x번 칸에 도착하면, y번 칸으 www.acmicpc.net # 2023.01.17 import sys input = sys.stdin.readline from collections import deque n, m = map(int, input().split()) # 사다리, 뱀 graph=[i for i in range(101)] # 0~100까지 게임판 for i in range(n+m): a, b = ma.. 2023. 1. 18.