๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

4๏ธโƒฃ Python56

[Python Algorithm] ํŒŒ๋„๋ฐ˜ ์ˆ˜์—ด BOJ #9461 ๋ฌธ์ œ https://www.acmicpc.net/problem/9461 9461๋ฒˆ: ํŒŒ๋„๋ฐ˜ ์ˆ˜์—ด ์˜ค๋ฅธ์ชฝ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์‚ผ๊ฐํ˜•์ด ๋‚˜์„  ๋ชจ์–‘์œผ๋กœ ๋†“์—ฌ์ ธ ์žˆ๋‹ค. ์ฒซ ์‚ผ๊ฐํ˜•์€ ์ •์‚ผ๊ฐํ˜•์œผ๋กœ ๋ณ€์˜ ๊ธธ์ด๋Š” 1์ด๋‹ค. ๊ทธ ๋‹ค์Œ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ ์ •์‚ผ๊ฐํ˜•์„ ๊ณ„์† ์ถ”๊ฐ€ํ•œ๋‹ค. ๋‚˜์„ ์—์„œ ๊ฐ€์žฅ ๊ธด ๋ณ€์˜ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด t = int(input()) memory = [1, 1, 1, 2, 2, 3, 4, 5, 7, 9] n = [] for _ in range(0, t): n.append(int(input())) if max(n) > 10: num = 10 while num < max(n): memory.append(memory[num-1] + memory[num-5]) num += 1 for i i.. 2021. 11. 16.
[Python Algorithm] 01ํƒ€์ผ BOJ #1904 ๋ฌธ์ œ https://www.acmicpc.net/problem/1904 1904๋ฒˆ: 01ํƒ€์ผ ์ง€์›์ด์—๊ฒŒ 2์ง„ ์ˆ˜์—ด์„ ๊ฐ€๋ฅด์ณ ์ฃผ๊ธฐ ์œ„ํ•ด, ์ง€์›์ด ์•„๋ฒ„์ง€๋Š” ๊ทธ์—๊ฒŒ ํƒ€์ผ๋“ค์„ ์„ ๋ฌผํ•ด์ฃผ์…จ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด ๊ฐ๊ฐ์˜ ํƒ€์ผ๋“ค์€ 0 ๋˜๋Š” 1์ด ์“ฐ์—ฌ ์žˆ๋Š” ๋‚ฑ์žฅ์˜ ํƒ€์ผ๋“ค์ด๋‹ค. ์–ด๋Š ๋‚  ์ง“๊ถ‚์€ ๋™์ฃผ๊ฐ€ ์ง€์›์ด www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) if n == 1: print(1) elif n == 2: print(2) else: memory = [1, 2] for i in range(2, n): memory.append((memory[i-2] + memory[i-1]) % 15746) print(memory[n-1]) ๐Ÿ‘‰DP ๋ฌธ์ œ๋กœ, ์ ํ™”์‹๊ณผ ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ํ‘ธ๋Š”๊ฒŒ ํฌ์ธํŠธ! [์ ํ™”.. 2021. 11. 16.
[Python Algorithm] ์‹ ๋‚˜๋Š” ํ•จ์ˆ˜ ์‹คํ–‰ BOJ #9184 ๋ฌธ์ œ https://www.acmicpc.net/problem/9184 9184๋ฒˆ: ์‹ ๋‚˜๋Š” ํ•จ์ˆ˜ ์‹คํ–‰ ์ž…๋ ฅ์€ ์„ธ ์ •์ˆ˜ a, b, c๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์˜ ๋งˆ์ง€๋ง‰์€ -1 -1 -1๋กœ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ์„ธ ์ •์ˆ˜๊ฐ€ ๋ชจ๋‘ -1์ธ ๊ฒฝ์šฐ๋Š” ์ž…๋ ฅ์˜ ๋งˆ์ง€๋ง‰์„ ์ œ์™ธํ•˜๋ฉด ์—†๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด memory = [[[0]*21 for _ in range(21)] for __ in range(21)] def w(a, b, c): if (a 20): return w(20, 20, 20) if memory[a][b][c]: return memory[a][b][c] # ์ด๋ฏธ abc ๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” memory ์ž๋ฆฌ์— ๊ฐ’์ด ํ• ๋‹น๋˜์–ด ์žˆ๋‹ค๋ฉด(0์ด ์•„๋‹ˆ๋ผ๋ฉด), ์—ฐ์‚ฐ ํ•„์š” ์—†์œผ๋ฏ€๋กœ ๊ทธ๋Œ€๋กœ.. 2021. 11. 16.
[Python Algorithm] ํ”ผ๋ณด๋‚˜์น˜ ํ•จ์ˆ˜ BOJ #1003 ๋ฌธ์ œ https://www.acmicpc.net/problem/1003 1003๋ฒˆ: ํ”ผ๋ณด๋‚˜์น˜ ํ•จ์ˆ˜ ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค 0์ด ์ถœ๋ ฅ๋˜๋Š” ํšŸ์ˆ˜์™€ 1์ด ์ถœ๋ ฅ๋˜๋Š” ํšŸ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด t = int(input()) nums = [] for i in range(t): nums.append(int(input())) memory = [] for i in range(max(nums)+1): if i == 0: memory.append([1, 0]) elif i == 1: memory.append([0, 1]) else: memory.append([memory[i-1][0]+memory[i-2][0], memory[i-1][1]+memory[i-2][1]]) fo.. 2021. 11. 16.
[Python] ๋ฆฌ์ŠคํŠธ ๊ด€๋ จ ํ•จ์ˆ˜ ์ด์ •๋ฆฌ! ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑํ•˜๋Š” ๋ฒ• ๋ถ€ํ„ฐ ์‚ญ์ œ, ์ˆ˜์ •, ์—ฐ์‚ฐ ๋“ฑ์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ž์ฃผ! ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜๋“ค์„ ๋ชจ๋‘ ์ •๋ฆฌํ•ด์„œ ์—…๋กœ๋“œํ•œ๋‹ค. ๐Ÿ“Œ ์ƒ์„ฑ """ 1์ฐจ์› ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ """ # ๋น„์–ด์žˆ๋Š” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ a = [] b = list() print(a, b) # [] [] # ๋ฐ˜๋ณต๋œ ๊ฐ’ ์ €์žฅํ•˜์—ฌ ์ƒ์„ฑ c = [0] * 10 print(c) # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # ๋‹ค์–‘ํ•œ ํƒ€์ž…์„ ํ•œ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ•˜๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅ d = ['a', 0, True] # ๋ฒ”์œ„ ์ง€์ •ํ•ด์„œ ์ƒ์„ฑ e = list(range(5)) f = list(range(1, 5)) g = list(range(1, 5, 2)) print(e, f, g) # [0, 1, 2, 3, 4] [1, 2, 3, 4] [1, 3] # map ํ•จ์ˆ˜.. 2021. 11. 15.