[백준 1182번] 부분수열의 합
1182번: 부분수열의 합 첫째 줄에 정수의 개수를 나타내는 N과 정수 S가 주어진다. (1 ≤ N ≤ 20, |S| ≤ 1,000,000) 둘째 줄에 N개의 정수가 빈 칸을 사이에 두고 주어진다. 주어지는 정수의 절댓값은 100,000을 넘지 않는다. www.acmicpc.net n, s = map(int,input().split()) # N개의 정수로 이루어진 수열, 부분수열의 원소를 다 더한 값이 S가 되는 경우의 수 data = list(map(int,input().split())) count = 0 visited = [False]*n def dfs(total,index,depth): global count if total == s and depth != 0: count += 1 for i in ..
2023. 10. 20.
[백준 2589번] 보물섬
2589번: 보물섬 보물섬 지도를 발견한 후크 선장은 보물을 찾아나섰다. 보물섬 지도는 아래 그림과 같이 직사각형 모양이며 여러 칸으로 나뉘어져 있다. 각 칸은 육지(L)나 바다(W)로 표시되어 있다. 이 지도에서 www.acmicpc.net import sys from collections import deque input = sys.stdin.readline dx = [-1,1,0,0] dy = [0,0,-1,1] # L : 육지, W : 바다 max_value = float("-inf") n, m = map(int,input().split()) area = [list(input().rstrip()) for _ in range(n)] def bfs(x,y): global max_value visite..
2023. 10. 20.
[백준 14889번] 스타트와 링크
14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net n = int(input()) visited = [False for _ in range(n)] data = [list(map(int, input().split())) for _ in range(n)] min_value = float("inf") def dfs(depth,index): global min_value if depth == n//2: power1, power2 = 0, 0 for i in range(n): for j in range(n): if visited[i] and v..
2023. 10. 19.
[백준 7562번] 나이트의 이동
7562번: 나이트의 이동 체스판 위에 한 나이트가 놓여져 있다. 나이트가 한 번에 이동할 수 있는 칸은 아래 그림에 나와있다. 나이트가 이동하려고 하는 칸이 주어진다. 나이트는 몇 번 움직이면 이 칸으로 이동할 수 www.acmicpc.net from collections import deque t = int(input()) dx = [-1,-2,-2,-1,1,2,2,1] dy = [-2,-1,1,2,-2,-1,1,2] for _ in range(t): n = int(input()) start_x, start_y = map(int,input().split()) dest_x, dest_y = map(int,input().split()) visited = [[-1]*n for _ in range(n)] d..
2023. 10. 18.