전체 글
-
3980. [Python]선발 명단Python_알고리즘/Gold V 2024. 10. 21. 18:40
1. 문제 https://www.acmicpc.net/problem/3980 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB백트래킹브루트 포스 3. 파이썬 코드 import sysinput = sys.stdin.readline# 백트래킹def DFS(start): # 최대값 저장 global max_value # 값 저장 global value # 최종 11에 도달했을 때 if start == 11: # 최대 값보다 값이 크면 갱신 if max_value 4. 문제를 풀고난 후 생각 모든 경우의 수를 다 탐색하면서 알고리즘을 돌리면 된다.백트래킹을 진행하되 0 번인덱스를 기준으로 백트래킹을 해주면 원하는 결과값이 나온다.테스트 케이스 개..
-
14502. [Python]연구소Python_알고리즘/Gold IV 2024. 10. 17. 21:06
1. 문제 https://www.acmicpc.net/problem/14502 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB그래프 탐색브루트 포스 3. 파이썬 코드 from itertools import combinations# DFS 로직def DFS(start): stack = [start] global max_value global check_cnt while stack: next = stack.pop() for k in range(4): ny = next[0] + direction[k][0] nx = next[1] + direction[k][1] if 0 max_value: ..
-
2631. [Python]줄세우기Python_알고리즘/Gold IV 2024. 10. 12. 02:04
1. 문제 https://www.acmicpc.net/problem/2631 2. 접근 방법 시간 제한: 1초메모리 제한: 128MBLIS(DP) 알고리즘 3. 파이썬 코드 import sysinput = sys.stdin.readlineN = int(input())num_list = []# 숫자 리스트 추가for _ in range(N): num_list.append(int(input()))# LIS 알고리즘 적용할 리스트long_length = [0] * N# LIS 알고리즘for i in range(N): # i 번 값 1로 초기화 long_length[i] = 1 # 0번 인덱스부터 i 번 인덱스까지 반복문진행 for j in range(0,i): # i 번..
-
1469. [Python]숌 사이 수열Python_알고리즘/Gold V 2024. 10. 8. 22:34
1. 문제 https://www.acmicpc.net/problem/1469 2. 접근 방법 시간 제한: 2초메모리 제한: 128MB브루트 포스백트래킹 3. 파이썬 코드 import sys# 재귀 제한 해제sys.setrecursionlimit(10000)# 백트래킹def backtracking(cnt): # 리스트 2배의 길이가 됐을때 종료 if cnt == N*2: print(*answer) exit() return # 리스트 안의 값 순회 for value in num_list: # 딕셔너리 값이 존재할 경우 if num_dict[value] > 0: # 딕셔너리 값이 2인 경우 백트래킹 ..
-
2533. [Python]사회망 서비스Python_알고리즘/Gold III 2024. 10. 3. 21:40
1. 문제 2. 접근 방법 시간 제한: 3초메모리 제한: 256MB트 3. 파이썬 코드 import sys# 많은 인풋 처리input = sys.stdin.readlineN = int(input())# 그래프 연결graph = [ [] for _ in range(N+1)]# 방문 처리visited = [ 0 for _ in range(N+1) ]# 양방향 그래프for _ in range(N-1): S,E = map(int,input().split()) graph[S].append(E) graph[E].append(S)# 리프 노드 저장leaf_node = []# 리프 노드에 값 저장for i in range(1,N+1): if len(graph[i]) == 1: lea..
-
14719. [Python]빗물Python_알고리즘/Gold V 2024. 9. 30. 20:15
1. 문제 https://www.acmicpc.net/problem/14719 2. 접근 방법 시간 제한: 1초메모리 제한: 256MB구현 3. 파이썬 코드 # H, W 인풋 처리H, W = map(int,input().split())# 빗물의 양 리스트로 저장rains = list(map(int,input().split()))# 몇칸이 쌓이는지 저장할 변수answer = 0# 1 ~ W-2 까지 반복for i in range(1,W-1): # i 값을 기준으로 왼쪽에서 제일 큰 값 찾기 left_value = max(rains[:i]) # i 값을 기준으로 오른쪽에서 제일 큰 값 찾기 right_value = max(rains[i:]) # 두 값중 작은 값 찾기 min_..
-
16235. [Python]나무 재테크Python_알고리즘/Gold III 2024. 9. 27. 17:51
1. 문제 https://www.acmicpc.net/problem/16235 2. 접근 방법 시간 제한: 1.3초메모리 제한: 512MB구현시뮬레이션 3. 파이썬 코드 import sysfrom collections import dequeinput = sys.stdin.readlineN, M, K = map(int,input().split())# 방향배열direction = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]# 양분 초기값matrix = [[5] * N for _ in range(N)]# 겨울 양분 값winter = []# 양분 추가for _ in range(N): winter.append(list(map(int,input().sp..
-
1520. [Python]내리막길Python_알고리즘/Gold III 2024. 9. 24. 16:03
1. 문제 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB재귀DP그래프 탐색 3. 파이썬 코드 import sys# 재귀 제한 해제sys.setrecursionlimit(100000)input = sys.stdin.readlineN, M = map(int,input().split())matrix = []# 방문 체크visited = [[-1] * M for _ in range(N)]for _ in range(N): matrix.append(list(map(int,input().split())))direction = [(0,-1),(-1,0),(0,1),(1,0)]# 백트래킹def backtracking(start): global cnt # 끝에 도달하면 1 리턴 if st..
-
1937. [Python]욕심쟁이 판다Python_알고리즘/Gold III 2024. 9. 20. 18:36
1. 문제 2. 접근 방법 시간 제한: 2초메모리 제한: 256MB재귀깊이우선 탐색DP 3. 파이썬 코드 import sys# 재귀 제한sys.setrecursionlimit(10000)# DFS 실행def DFS(start): global max_value global N # 온 경로가 방문한 곳일 경우 if visited[start[0]][start[1]] != 0: # 현재 돌아온 경로를 리턴 return visited[start[0]][start[1]] # 시작 값 1로 초기화 visited[start[0]][start[1]] = 1 for k in range(4): ny = direction[k][0] + start[0..
-
10159. [Python]저울Python_알고리즘/Gold IV 2024. 9. 19. 18:08
1. 문제 https://www.acmicpc.net/problem/10159 2. 접근 방법 시간 제한: 1초메모리 제한: 256MB최단거리플로이드 와샬 3. 파이썬 코드 import sysinput = sys.stdin.readlineN = int(input())M = int(input())# 초기 그래프 선언graph = [[0] * (N+1) for _ in range(N+1)]# 들어온 인풋에 대해서 누가 더 큰지 체크for _ in range(M): S,E = map(int,input().split()) graph[S][E] = 1# i,i 인덱스 0으로 초기화for i in range(N+1): graph[i][i] = 0# 플로이드 와샬for i in range(1,N+1..