문제풀이

·문제풀이/DP
https://www.acmicpc.net/problem/3372 코드n = int(input())board = [list(map(int, input().split())) for _ in range(n)]dp = [[0]*n for _ in range(n)]dp[0][0] = 1for i in range(n): for j in range(n): if board[i][j] == 0: continue # 오른쪽 if j+board[i][j]  dp[i][j]는 (i, j)까지 갈 수 있는 경로의 수를 저장한다. 출발점인 (0, 0)의 dp값을 1로 놓고, N × N 게임 보드의 각 칸을 살펴보며 현재 칸(i, j)에서 오른쪽과 아래로 board[..
https://www.acmicpc.net/problem/20665 코드n, t, p = map(int, input().split())time = []for _ in range(t): s, e = map(int, input().split()) s = s//100*60+s % 100 e = e//100*60+e % 100 time.append((s, e))time.sort()ans = 60*12def find_seat(arr): # 앉을 자리 선택 if not arr: # 아무도 없는 경우 return 1 candidate = [] # 앉을 자리 후보 if arr[0][0] != 1: # 1번 좌석 candidate.append((arr..
https://www.acmicpc.net/problem/15823 코드import sysinput = sys.stdin.readlinen, m = map(int, input().split())arr = list(map(int, input().split()))def chk(num): # Two Pointer pack = set() l, r = 0, 0 cnt = 0 while r  50점만 받을 수 있는 코드이다.Parametric Search과 Two Pointer 알고리즘을 사용했는데, Parametric Search에서 조건을 검사할 때 Two Pointer를 사용한다. bs() : Parametric Search하나의 카드 팩을 구성할 수 있는 최대 카드 수를 Parame..
https://www.acmicpc.net/problem/1269 코드a_num, b_num = map(int, input().split())a = set(map(int, input().split()))b = set(map(int, input().split()))print(len(a-b)+len(b-a)) 파이썬은 집합 자료형과 관련 연산이 정의되어 있어서 이 문제를 쉽게 풀 수 있었다. a와 b를 set()을 이용하여 집합으로 만들고, '-' 연산을 이용하여 A-B와 B-A 차집합을 구한 뒤 두 차집합의 길이를 더해주면 된다
https://www.acmicpc.net/problem/14248 코드from collections import dequen = int(input())a = list(map(int, input().split()))start = int(input())-1q = deque([start])visited = [False]*nvisited[start] = Trueans = 1while q: now = q.popleft() # 왼쪽, 오른쪽 for nx in [now-a[now], now+a[now]]: if 0  단순히 각 돌에 방문할 수 있는지 여부만 판단하면 되기 때문에 BFS를 이용하여 갈 수 있는 돌들을 방문하며 개수를 세면 된다.
딜레이레이
'문제풀이' 카테고리의 글 목록 (10 Page)