-
Notifications
You must be signed in to change notification settings - Fork 5
Minjeong / 12월 2주차 / 4문제 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
minjeong/DynamicProgramming/2024-12-14-[백준]-#10844-쉬운계단수.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| n = int(input()) | ||
|
|
||
| num = [[0]*10 for _ in range(n+1)] | ||
| num[0] = [1,1,1,1,1,1,1,1,0] #0행에 들어가는 값들을 계단수의 경우의수로 초기화 | ||
|
|
||
| for i in range(1,n+1): | ||
| for j in range(10): #0일때, 9일때, 나머지인 경우를 점화식을 토대로 코드 작성 | ||
| if j == 0: | ||
| num[i][j] = num[i-1][1] | ||
| elif j == 9: | ||
| num[i][j] = num[i-1][8] | ||
| else: | ||
| num[i][j] = num[i-1][j-1] + num[i-1][j] | ||
|
|
||
| answer = sum(num[n]) % 100000000 | ||
| print(answer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 하노이 함수 | ||
| def hanoi_f(one, three, n): | ||
| if n == 1: | ||
| print(one, three) | ||
| return | ||
|
|
||
| hanoi_f(one, 6 - one - three, n - 1) # 1단계 (1->2) | ||
| print(one, three) # 2단계 (마지막원반 1->3) | ||
| hanoi_f(6 - one - three, three, n - 1) # 3단계 (2->3) | ||
|
|
||
|
|
||
| # 메인 | ||
| n = int(input()) | ||
| print(2 ** n - 1) | ||
| if n <= 20: | ||
| hanoi_f(1, 3, n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import sys | ||
| input = sys.stdin.readline | ||
|
|
||
| # 누적합 테이블 계산 | ||
| def get_prefix_sum(grid, N): | ||
| prefix_sum = [[0] * (N+1) for _ in range(N+1)] | ||
| for i in range(1, N+1): | ||
| for j in range(1, N+1): | ||
| prefix_sum[i][j] = ( | ||
| grid[i-1][j-1] | ||
| + prefix_sum[i-1][j] | ||
| + prefix_sum[i][j-1] | ||
| - prefix_sum[i-1][j-1] | ||
| ) | ||
| return prefix_sum | ||
|
|
||
| # 입력 | ||
| N, M = map(int, input().split()) | ||
| grid = [list(map(int, input().split())) for _ in range(N)] | ||
|
|
||
| # 누적합 | ||
| prefix_sum = get_prefix_sum(grid, N) | ||
|
|
||
| # 범위 합 계산 | ||
| for _ in range(M): | ||
| x1, y1, x2, y2 = map(int, input().split()) | ||
| answer = ( | ||
| prefix_sum[x2][y2] | ||
| - prefix_sum[x1-1][y2] | ||
| - prefix_sum[x2][y1-1] | ||
| + prefix_sum[x1-1][y1-1] | ||
| ) | ||
| print(answer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| n, m = map(int, input().split()) | ||
| graph = [list(map(int, input().split())) for _ in range(n)] | ||
| visited = [[False] * m for _ in range(n)] | ||
|
|
||
| # 방향 설정 (상, 하, 좌, 우) | ||
| dx = [-1, 1, 0, 0] | ||
| dy = [0, 0, -1, 1] | ||
|
|
||
| # 최댓값 저장 변수 | ||
| max_value = 0 | ||
|
|
||
|
|
||
| # DFS 탐색 (ㅗ 모양 제외) | ||
| def dfs(x, y, count, total): | ||
| global max_value | ||
| # 테트로미노 4칸 채웠을 경우 | ||
| if count == 4: | ||
| max_value = max(max_value, total) | ||
| return | ||
|
|
||
| # 상하좌우 탐색 | ||
| for i in range(4): | ||
| nx, ny = x + dx[i], y + dy[i] | ||
| # 범위 내에 있고, 방문하지 않은 경우 | ||
| if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny]: | ||
| visited[nx][ny] = True | ||
| dfs(nx, ny, count + 1, total + graph[nx][ny]) | ||
| visited[nx][ny] = False # 백트래킹 | ||
Mingguriguri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # ㅗ 모양 탐색 | ||
| def check_t_shape(x, y): | ||
Mingguriguri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| global max_value | ||
| # 중심 기준 4방향 중 3개를 선택 (ㅗ, ㅜ, ㅏ, ㅓ) | ||
| for i in range(4): | ||
| total = graph[x][y] | ||
| for j in range(3): # 현재 제외한 3방향 탐색 | ||
| k = (i + j) % 4 | ||
| nx, ny = x + dx[k], y + dy[k] | ||
| if 0 <= nx < n and 0 <= ny < m: | ||
| total += graph[nx][ny] | ||
| else: # 범위를 벗어나면 ㅗ 모양이 성립하지 않음 | ||
| break | ||
| else: # 모든 3방향 탐색이 유효한 경우 | ||
| max_value = max(max_value, total) | ||
|
|
||
|
|
||
| # 모든 좌표에서 테트로미노 탐색 | ||
| for i in range(n): | ||
| for j in range(m): | ||
| visited[i][j] = True | ||
| dfs(i, j, 1, graph[i][j]) # DFS 시작 | ||
| visited[i][j] = False | ||
| check_t_shape(i, j) # ㅗ 모양 탐색 | ||
|
|
||
| # 결과 출력 | ||
| print(max_value) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.