전체 글

전체 글

    스도쿠 풀이

    문제 링크: https://www.acmicpc.net/problem/2580 백준 알고리즘 중급 1/3 531에서 10번째 - 2580번 스도쿠를 풀어보았다. 풀이: https://www.acmicpc.net/source/55113635 C++ Python a = [list(map(int, input().split())) for _ in range(9)] b, n = [0]*81, 0 row = [[False]*10 for _ in range(9)] col = [[False]*10 for _ in range(9)] squ = [[False]*10 for _ in range(9)] def s(i, j): return i//3*3 + j//3 def solve(idx): if idx == n: for i ..

    N-Queen 풀이

    문제 링크: https://www.acmicpc.net/problem/9663 백준 알고리즘 중급 1/3 531에서 9번째 - 9663번 N-Queen를 풀어보았다. 풀이: https://www.acmicpc.net/source/56230329 C++ Python def bt(x): global cnt if x == n: cnt += 1 for i in range(n): if visited_1[i] or visited_2[i-x] or visited_3[i+x]: continue visited_1[i] = 1 visited_2[i-x] = 1 visited_3[i+x] = 1 bt(x+1) visited_1[i] = 0 visited_2[i-x] = 0 visited_3[i+x] = 0 n = int(i..

    에너지 모으기 풀이

    문제 링크: https://www.acmicpc.net/problem/16198 백준 알고리즘 중급 1/3 531에서 8번째 - 16198번 에너지 모으기를 풀어보았다. 풀이: https://lemonjade.tistory.com/m/11 를 참고했다. C++ Python def dfs(arr,tot): global res if len(arr)==2: res=max(res,tot) return for i in range(1,len(arr)-1): dfs(arr[:i]+arr[i+1:],tot+(arr[i-1]*arr[i+1])) n=int(input()) nums=list(map(int,input().split())) res=0 dfs(nums,res) print(res) Java

    두 동전 풀이

    문제 링크: https://www.acmicpc.net/problem/16197 백준 알고리즘 중급 1/3 531에서 7번째 - 16197번 두 동전을 풀어보았다. 풀이: https://pottatt0.tistory.com/entry/%EB%B0%B1%EC%A4%80-16197-%ED%95%B4%EC%84%A4-python-%EB%91%90-%EB%8F%99%EC%A0%84 C++ Python import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N,M = map(int,input().split()) board = [list(input().rstrip()) for _ in range(N)] visited = [] coinpos = [] d..

    연산자 끼워넣기 (2) 풀이

    문제 링크: https://www.acmicpc.net/problem/15658 백준 알고리즘 중급 1/3 531에서 5번째 - 15658번 연산자 끼워넣기 (2)를 풀어보았다. 풀이: 연산자 끼워넣기 코드를 그대로 쓰면 풀린다. C++ Python def dfs(dep,tot,pl,mi,mu,di): global maxs,mins if dep==n: maxs=max(tot,maxs) mins=min(tot,mins) return if pl: dfs(dep+1,tot+nums[dep],pl-1,mi,mu,di) if mi: dfs(dep+1,tot-nums[dep],pl,mi-1,mu,di) if mu: dfs(dep+1,tot*nums[dep],pl,mi,mu-1,di) if di: dfs(dep+1,..

    14225번 부분수열의 합 풀이

    문제 링크: https://www.acmicpc.net/problem/14225 백준 알고리즘 중급 1/3 531에서 3번째 - 14225번 부분수열의 합을 풀어보았다. 풀이: 1182번 부분수열의 합에서 썼던 코드를 이용했다. C++ Python from itertools import combinations n=int(input()) s=list(map(int,input().split())) nums=[0 for i in range(2000001)] for i in range(1,n+1): a=combinations(s,i) for b in a: k=sum(b) nums[k]+=1 for i in range(1,2000001): if nums[i]==0: print(i) break Java

    연산자 끼워넣기 풀이

    문제 링크: https://www.acmicpc.net/problem/14888 백준 알고리즘 중급 1/3 521에서 3번째 - 14888번 연산자 끼워넣기를 풀어보았다. 풀이: https://velog.io/@kimdukbae/BOJ-14888-%EC%97%B0%EC%82%B0%EC%9E%90-%EB%81%BC%EC%9B%8C%EB%84%A3%EA%B8%B0-Python 를 참고했다. C++ Python def dfs(dep,tot,pl,mi,mu,di): global maxs,mins if dep==n: maxs=max(tot,maxs) mins=min(tot,mins) return if pl: dfs(dep+1,tot+nums[dep],pl-1,mi,mu,di) if mi: dfs(dep+1,tot..

    단어 수학 풀이

    문제 링크: https://www.acmicpc.net/problem/1339 백준 알고리즘 중급 1/3 521에서 2번째 - 1339번 단어 수학을 풀어보았다. 풀이: https://velog.io/@dding_ji/baekjoon-1339 를 참고했다. C++ Python n=int(input()) alpha=[0 for i in range(26)] for i in range(n): inp=input().rstrip() for j in range(len(inp)): alpha[ord(inp[j])-ord('A')]+=10**(len(inp)-j-1) alpha.sort() res=0 num=9 for i in range(25,0,-1): if alpha[i]==0 or num