1N = int(input()) 2 3L = [list(map(int, input().split())) for _ in range(N)] 4result = 0 5 6def dfs(x, y, direc): 7 global result 8 if x == N-1 and y == N-1: 9 result += 1 10 return 11 12 if x+1 < N and y+1 < N and L[y+1][x] == 0 and L[y][x+1] == 0 and L[y+1][x+1] == 0: 13 dfs(x+1, y+1, 2) 14 15 if (direc == 0 or direc == 2) and x+1 < N and L[y][x+1] == 0: 16 dfs(x+1, y, 0) 17 18 if (direc == 1 or direc == 2) and y+1 < N and L[y+1][x] == 0: 19 dfs(x, y+1, 1) 20 21dfs(1, 0, 0) 22print(result) ๋ณ๊ฑฐ ์๋๊ฒ.
1N, M = map(int, input().split()) 2 3L = [list(map(int, input())) for _ in range(N)] 4 5dp = [[0]*(M+1) for _ in range(N+1)] 6 7result = 0 8 9for i in range(1, N+1): 10 for j in range(1, M+1): 11 dp[i][j] = L[i-1][j-1] 12 13 if L[i-1][j-1]: 14 dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])+1 15 result = max(result, dp[i][j]) 16 17for i in dp: 18 print (i) 19print (result**2) ์กฐ๊ธ ์๊ฐ์ด ๊ฑธ๋ ธ์ง๋ง ํผ์ ํ์ผ๋ก ํ์๋ค ์ ํ์์ dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])+1์ด๋ค.
1D, K = map(int, input().split()) 2L = [(1, 0), (0, 1)] 3 4for i in range(2, D): 5 L.append((L[i-2][0]+L[i-1][0], L[i-2][1]+L[i-1][1])) 6 7A = 1 8B = 2 9 10while True: 11 if A*L[D-1][0] + B*L[D-1][1] == K: 12 break 13 14 if A+1 == B: 15 B += 1 16 A = 1 17 else: 18 A += 1 19 20print (A,'\n',B, sep='') ํด๊ฒฐ๋ฐฉ๋ฒ N๋ฒ์งธ๋ ๋ก ๊ฐ์๋ฅผ ๊ตฌํ๊ธฐ ์ํด ์ฒซ์งธ๋ ๋ก, ๋์งธ๋ ๋ก์ ๊ฐ๊ฐ ๋ช๋ฒ ๋ํด์ผํ๋์ง ๋ฆฌ์คํธ์ ๊ตฌํ๋ค ์ฒซ์งธ, ๋์งธ ๋ ๋ก์ ํ๋ํ๋ ๋ฃ์ด๋ณด๋ฉด์ ๋ธ๋ฃจํธ ํฌ์ค๋ฅผ ์ํํ๋ค
1import sys 2sys.setrecursionlimit(10**6) 3M = int(input()) 4G = [[] for _ in range(M)] 5 6for _ in range(M-1): 7 a, b, c = map(int, input().split()) 8 G[a-1].append((b-1, c)) 9 G[b-1].append((a-1, c)) 10 11n1 = 0 12tmp = 0 13 14def dfs(node, length): 15 global n1, tmp 16 visit[node] = True 17 if length > tmp: 18 tmp = length 19 n1 = node 20 for child, v in G[node]: 21 if not visit[child]: 22 dfs(child, length+v) 23 24visit = [False]*M 25dfs(0, 0) 26tmp = 0 27visit = [False]*M 28dfs(n1, 0) 29print (tmp) ์ธํฐ๋ท์์ ์ ๊ทผ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํ๋ค ํด๊ฒฐ ๋ฐฉ๋ฒ ์๋ฌด ์ ์ ์์ ๊ฐ์ฅ ๋จผ ์ด๋ค ์ ์ ์ N์ด๋ผ๊ณ ํ์ ์ ์ N์์ ๊ฐ์ฅ ๋จผ ์ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๊ฐ ํธ๋ฆฌ์ ์ง๋ฆ๊ณผ ๊ฐ๋ค ๋๋ ์ ๋ฃจํธ๋ฅผ ๊ตฌํ ํ์๊ฐ ์๋ค๋ ๊ฒ์ ๊นจ๋ฌ์๋ค
1import sys 2sys.setrecursionlimit(10**6) 3input = sys.stdin.readline 4 5V = int(input()) 6G = [[] for _ in range(V)] 7for _ in range(V): 8 token = list(map(int, input().split()))[:-1] 9 for i in range(1, len(token), 2): 10 G[token[0]-1].append((token[i]-1, token[i+1])) 11 12def dfs(node, dist): 13 global max_node, max_dist 14 visited[node] = True 15 if dist > max_dist: 16 max_node = node 17 max_dist = dist 18 for n_node, n_dist in G[node]: 19 if not visited[n_node]: 20 dfs(n_node, dist+n_dist) 21 22max_node = 0 23 24max_dist = 0 25visited = [False]*V 26dfs(0, 0) 27max_dist = 0 28visited = [False]*V 29dfs(max_node, 0) 30 31print (max_dist) ์ต๊ทผ์ ํผ “1967: ํธ๋ฆฌ์ ์ง๋ฆ” ๋๋ถ์ ์ฝ๊ฒ ํด๊ฒฐํ ์ ์์๋ค ๊ธฐ์ตํ์ ํธ๋ฆฌ์ ์ง๋ฆ = (์ด๋ค ํ ์ ์ ์์ ๊ฐ์ฅ ๋จผ ์ P)์์ ๊ฐ์ฅ ๋จผ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ
1N, M, R = map(int, input().split()) 2 3item = list(map(int, input().split())) 4G = [[] for _ in range(N)] 5for _ in range(R): 6 a, b, c = map(int, input().split()) 7 G[a-1].append((b-1, c)) 8 G[b-1].append((a-1, c)) 9 10def dfs(node, dist): 11 global result 12 if dist > M: 13 return 14 if not visit[node]: 15 result += item[node] 16 visit[node] = True 17 18 for n_node, n_dist in G[node]: 19 dfs(n_node, dist+n_dist) 20 21max_result = 0 22 23for i in range(N): 24 result = 0 25 visit = [False]*N 26 dfs(i, 0) 27 max_result = max(max_result, result) 28 29print (max_result) ๋ถ๋ฅ์ ๋ค์ต์คํธ๋ผ, ํ๋ก์ด๋-์์
๋ก ๋์ด์์ง๋ง DFS๋ก ํ์๋ค ํ์ด ๋ฐฉ๋ฒ ์ฌ๊ธฐ์๋ ์ฌ๋ฐฉ๋ฌธ ํ๋ค๊ณ ํด์ ํ์์ ํ์ง ์์ผ๋ฉด ์๋๋ค ์ฌ๋ฐฉ๋ฌธํ์๋ ์ ์ ๋ฐฉ๋ฌธํ์ ๋๋ณด๋ค ๋ ์งง์ ํต๋ก๋ก ๋ค์ด์๋ค๋ฉด ๋ ๋ง์ ์์ดํ
์ ์ป์ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค ๋ค๋ง, ์์ดํ
์ ๋ฐฉ๋ฌธํ ๋๋ง๋ค ์ป์ ์ ์๋ ๊ฒ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ฃผ์ํ์ฌ์ผ ํ๋ค ์์ ๋ด์ฉ์ ์ง๋ฌธ๊ฒ์ํ์ ๋ณด๋ค๊ฐ ๊นจ๋ซ๊ณ ํ ์ ์์๋ค