๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 479

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [DP] 2156๋ฒˆ_ํฌ๋„์ฃผ ์‹œ์‹

๋ฌธ์ œ https://www.acmicpc.net/problem/2156 2156๋ฒˆ: ํฌ๋„์ฃผ ์‹œ์‹ ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹ํšŒ์— ๊ฐ”๋‹ค. ๊ทธ ๊ณณ์— ๊ฐ”๋”๋‹ˆ, ํ…Œ์ด๋ธ” ์œ„์— ๋‹ค์–‘ํ•œ ํฌ๋„์ฃผ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํฌ๋„์ฃผ ์ž”์ด ์ผ๋ ฌ๋กœ ๋†“์—ฌ ์žˆ์—ˆ๋‹ค. ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹์„ ํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‘ ๊ฐ€์ง€ ๊ทœ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2156๋ฒˆ ๋ฌธ์ œ - ํฌ๋„์ฃผ ์‹œ์‹ n = int(input()) dp = [0]*10002 grape = [0]*10002 for i in range(1, n+1): grape[i] = int(input()) dp[1] = grape[1] dp[2] = grape[1] + grape[2] for i in range(3, n+1): dp[i] = max(dp[i-1], dp[i-3]..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [๊ตฌํ˜„] 15686๋ฒˆ_์น˜ํ‚จ ๋ฐฐ๋‹ฌ

๋ฌธ์ œ https://www.acmicpc.net/problem/15686 15686๋ฒˆ: ์น˜ํ‚จ ๋ฐฐ๋‹ฌ ํฌ๊ธฐ๊ฐ€ N×N์ธ ๋„์‹œ๊ฐ€ ์žˆ๋‹ค. ๋„์‹œ๋Š” 1×1ํฌ๊ธฐ์˜ ์นธ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋‹ค. ๋„์‹œ์˜ ๊ฐ ์นธ์€ ๋นˆ ์นธ, ์น˜ํ‚จ์ง‘, ์ง‘ ์ค‘ ํ•˜๋‚˜์ด๋‹ค. ๋„์‹œ์˜ ์นธ์€ (r, c)์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ๋‚˜ํƒ€๋‚ด๊ณ , rํ–‰ c์—ด ๋˜๋Š” ์œ„์—์„œ๋ถ€ํ„ฐ r๋ฒˆ์งธ ์นธ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 15686๋ฒˆ ๋ฌธ์ œ - ์น˜ํ‚จ ๋ฐฐ๋‹ฌ import sys from itertools import combinations input = sys.stdin.readline n, m = map(int, input().split()) graph = list(list(map(int, input().split())) for _ in range(n)) result = 999..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] 1987๋ฒˆ_์•ŒํŒŒ๋ฒณ

๋ฌธ์ œ https://www.acmicpc.net/problem/1987 1987๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์„ธ๋กœ R์นธ, ๊ฐ€๋กœ C์นธ์œผ๋กœ ๋œ ํ‘œ ๋ชจ์–‘์˜ ๋ณด๋“œ๊ฐ€ ์žˆ๋‹ค. ๋ณด๋“œ์˜ ๊ฐ ์นธ์—๋Š” ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์ด ํ•˜๋‚˜์”ฉ ์ ํ˜€ ์žˆ๊ณ , ์ขŒ์ธก ์ƒ๋‹จ ์นธ (1ํ–‰ 1์—ด) ์—๋Š” ๋ง์ด ๋†“์—ฌ ์žˆ๋‹ค. ๋ง์€ ์ƒํ•˜์ขŒ์šฐ๋กœ ์ธ์ ‘ํ•œ ๋„ค ์นธ ์ค‘์˜ ํ•œ ์นธ์œผ www.acmicpc.net ํ’€์ด import sys def bfs(): global cnt queue = set([(0, 0, graph[0][0])]) # ์‹œ๊ฐ„ ์ดˆ๊ณผ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด ์ค‘๋ณต๋˜๋Š” ๊ณณ์€ ์ œ๊ฑฐ while queue: x, y, z = queue.pop() # ๋ง์ด ์ง€๋‚  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€์˜ ์นธ ์ดˆ๊ธฐํ™” cnt = max(cnt, len(z)) # ์ƒ/ํ•˜/์ขŒ/์šฐ ํƒ์ƒ‰ for i in range(4): nx = ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] 1932๋ฒˆ_์ •์ˆ˜ ์‚ผ๊ฐํ˜•

๋ฌธ์ œ https://www.acmicpc.net/problem/1987 1987๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์„ธ๋กœ R์นธ, ๊ฐ€๋กœ C์นธ์œผ๋กœ ๋œ ํ‘œ ๋ชจ์–‘์˜ ๋ณด๋“œ๊ฐ€ ์žˆ๋‹ค. ๋ณด๋“œ์˜ ๊ฐ ์นธ์—๋Š” ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์ด ํ•˜๋‚˜์”ฉ ์ ํ˜€ ์žˆ๊ณ , ์ขŒ์ธก ์ƒ๋‹จ ์นธ (1ํ–‰ 1์—ด) ์—๋Š” ๋ง์ด ๋†“์—ฌ ์žˆ๋‹ค. ๋ง์€ ์ƒํ•˜์ขŒ์šฐ๋กœ ์ธ์ ‘ํ•œ ๋„ค ์นธ ์ค‘์˜ ํ•œ ์นธ์œผ www.acmicpc.net ํ’€์ด DP๋ฅผ ์ด์šฉํ•œ ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์ด๋‹ค. ๊ทœ์น™์„ ์ฐพ๋‹ค๋ณด๋ฉด ๋งค์šฐ ์‰ฝ๊ฒŒ ๋‚˜์˜จ๋‹ค. # ๋ฐฑ์ค€ 1932๋ฒˆ ๋ฌธ์ œ - ์ •์ˆ˜ ์‚ผ๊ฐํ˜• n = int(input()) dp = [] for _ in range(n): dp.append(list(map(int, input().split()))) for i in range(len(dp)): for j in range(len(dp[i])): if j == 0: d..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] 9933๋ฒˆ_๋ฏผ๊ท ์ด์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ

๋ฌธ์ œ https://www.acmicpc.net/problem/9933 9933๋ฒˆ: ๋ฏผ๊ท ์ด์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ์ˆ˜ N (2 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ ์ค„์—๋Š” ํŒŒ์ผ์— ์ ํ˜€์žˆ๋Š” ๋‹จ์–ด๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ๋‹จ์–ด๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ธธ์ด๋Š” 2๋ณด๋‹ค ํฌ๊ณ  14๋ณด๋‹ค ์ž‘์€ www.acmicpc.net ํ’€์ด import sys input = sys.stdin.readline N = int(input()) files = [input().rstrip() for _ in range(N)] for i in range(N-1): for j in range(i,N): if files[i][::-1] == files[j]: print(len(files[i]), files[i][len..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Class4] 12852๋ฒˆ_1๋กœ ๋งŒ๋“ค๊ธฐ 2

๋ฌธ์ œ https://www.acmicpc.net/problem/12852 12852๋ฒˆ: 1๋กœ ๋งŒ๋“ค๊ธฐ 2 ์ฒซ์งธ ์ค„์— 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 106๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ํ’€์ด BFS๋ฅผ ์ด์šฉํ•œ ํ’€์ด # ๋ฐฑ์ค€ 12852๋ฒˆ ๋ฌธ์ œ - 1๋กœ ๋งŒ๋“ค๊ธฐ 2 from collections import deque n = int(input()) q = deque() q.append((n,[n])) visited = [0]*(n+1) while q: num,ans = q.popleft() if num == 1: print(len(ans)-1) print(*ans) break if not visited[num]: visited[num]=1 if num%3==0: q.append((num..