일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Unreal Engine 5
- c++
- 문제풀이
- 시작해요 언리얼 2022
- w3school
- Basic
- 파이썬
- Programming
- C#
- Material
- 오류
- parameter
- dfs
- github
- Tutorial
- 백준
- 프로그래밍
- python
- dynamic
- String
- Algorithm
- Unity
- 재귀
- guide
- Class
- 기초
- DP
- loop
- UE5
- W3Schools
- Today
- Total
목록Algorithm (107)
행복한 개구리

from itertools import combinations N = int(input()) matrix = [list(map(int, input().split())) for i in range(N)] teamComb = list(combinations(range(N), N//2)) result = [] for i in range(len(teamComb)//2): teamS = teamComb[i] statS = 0 for j in range(N//2): colS = teamS[j] for rowS in teamS: statS += matrix[colS][rowS] teamL = teamComb[-i-1] statL = 0 for j in range(N//2): colL = teamL[j] for row..

N = int(input()) ops = [] nums = [] result = [] nums = list(map(int, input().split())) ops = list(map(int, input().split())) m = -1e9 n = 1e9 def DFS(num, depth, add, sub, mul, div): if depth == N: if num not in result: result.append(num) return if add > 0: DFS(num + nums[depth], depth + 1, add - 1, sub, mul, div) if sub > 0: DFS(num - nums[depth], depth + 1, add, sub - 1, mul, div) if mul > 0: ..

sudoku = [] blank = [] for i in range(9): sudoku.append(list(map(int, input().strip().split()))) for i in range(9): for j in range(9): if sudoku[i][j] == 0: blank.append((i, j)) def CheckRow(x, val): for i in range(9): if sudoku[x][i] == val: return False return True def CheckCol(y, val): for i in range(9): if sudoku[i][y] == val: return False return True def CheckSquare(x, y, val): startX = x /..

def N_Queen(idx): if idx == N: global result result += 1 return else: for i in range(N): queen[idx] = i if Promise(idx): N_Queen(idx + 1) def Promise(idx): for i in range(idx): if queen[idx] == queen[i] or abs(queen[idx] - queen[i]) == idx - i: return False return True N = int(input()) queen = [0] * N result = 0 N_Queen(0) print(result) python3는 시간초과에 걸린다는 글이 많아서 pypy3로 제출하여 통과했습니다 우선 queen리스트를 ..

import sys arr = [] def DFS(idx, n, m): if len(arr) == m: sys.stdout.write(" ".join(map(str, arr)) + "\n") return for i in range(idx, n + 1): arr.append(i) DFS(i, n, m) arr.pop() N, M = map(int, sys.stdin.readline().split()) DFS(1, N, M) DFS를 활용합니다. 하지만 유의해야할 점이 있는데, 비내림차순(인덱스가 커 질수록 요소들이 같거나 커짐)이므로 시작인덱스를 정해주는게 좋습니다. => 시작인덱스를 정해주면 해당 검색경로에 나오는 모든 값을 다 사용할 수 있기 때문입니다. 따라서 재귀를 통해 인덱스가 증가하며 비내림차순..

arr = [] def DFS(n, m): if len(arr) == m: print(" ".join(map(str, arr))) return for i in range(1, n+1): arr.append(i) DFS(n, m) arr.pop() N, M = map(int, input().split()) DFS(N, M) 결괏값을 제한하는 조건없이 모든 경우의 수를 탐색하는 코드를 작성해야합니다. 따라서 DFS를 사용하지만 조건은 추가하지 않은 채로 구현했습니다.