목록문제/백준_파이썬 (155)
sm 기술 블로그
import sys input = sys.stdin.readline N = int(input()) visited = [False] * N startLink = [list(map(int,input().split())) for _ in range(N)] result = [] def teamCalc(): startTeam = 0 LinkTeam = 0 for i in range(N): for j in range(i+1,N): if visited[i] and visited[j]: startTeam += startLink[i][j] startTeam += startLink[j][i] elif not visited[i] and not visited[j]: LinkTeam += startLink[i][j] LinkT..
import sys input = sys.stdin.readline N = int(input()) num = list(map(int, input().split())) operator = list(map(int, input().split())) # 덧셈, 뺄셈, 곱셈, 나눗셈 result = [] def DFS(add, sub, mul, div, value, depth): if depth == N: result.append(value) return if(add != 0): DFS(add-1, sub, mul, div, value + num[depth], depth+1) if(sub != 0): DFS(add, sub-1, mul, div, value - num[depth], depth+1) if(mul !..
이 코드는 pypy3에서 돌려야 시간초과가 발생하지 않습니다. import sys input = sys.stdin.readline sudoku = [list(map(int, input().split())) for _ in range(9)] def search(row, col, value): for i in range(9): if sudoku[row][i] == value: return False for i in range(9): if sudoku[i][col] == value: return False rowFirst = (row // 3) * 3 colFirst = (col // 3) * 3 for i in range(rowFirst, rowFirst+3): for j in range(colFirst, ..
※ 본 코드는 pypy3으로 제출해야 합니다. N = int(input()) visited = [False] * N QueenNum = [0] * N cnt = 0 def DFS(depth): global cnt if depth == N: cnt += 1 return for i in range(N): if not visited[i]: QueenNum[depth] = i isQLocated = False for j in range(depth): if abs(QueenNum[depth] - QueenNum[j]) == abs(depth-j): isQLocated = True break if not isQLocated: print(">>",i,depth,QueenNum[depth]) visited[i] = T..