Skip to content

Commit

Permalink
Merge pull request #204 from AlgoLeadMe/58-tgyuuAn
Browse files Browse the repository at this point in the history
58-tgyuuAn
  • Loading branch information
tgyuuAn authored Jun 3, 2024
2 parents a10a552 + 8cbce65 commit 5aee288
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tgyuuAn/DFS/λΉ„μˆ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def dfs(n, cnt):
global ans
# κ°€μ§€μΉ˜κΈ°: μ΄λŒ€λ‘œ 진행해도 μ •λ‹΅ κ°±μ‹  κ°€λŠ₯μ„± μ—†λŠ” 경우 더 이상 진행 X
if ans >= (cnt+(L+1-n)//2): # 남은 자리 λ‹€ 놓아도 μ •λ‹΅ κ°±μ‹  μ•ˆλ˜λŠ” 경우
return

if n>=L:
ans = max(ans, cnt)
return

for ci,cj in lst[n]: # ν˜„μž¬ μ‚¬μ„ λ²ˆν˜Έμ—μ„œ κ°€λŠ₯ν•œ μœ„μΉ˜ ν•˜λ‚˜μ”© 놓고 λ‹€μŒ μ‚¬μ„ μœΌλ‘œ..
if v[ci-cj]==0:
v[ci-cj]=1
dfs(n+2, cnt+1)
v[ci-cj]=0
dfs(n+2, cnt) # 이번 μ‚¬μ„ μ—μ„œ μ•ˆλ†“κ³  λ‹€μŒμ‚¬μ„ μœΌλ‘œ..

N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]

lst = [[] for _ in range(2*N)]
# arr[i][j]==1인경우 i+j μœ„μΉ˜μ— append
for i in range(N):
for j in range(N):
if arr[i][j]==1:
lst[i+j].append((i,j))
L = 2*N-1
v = [0]*(2*N)

# 체슀판의 흑/백은 λΉ„μˆμ΄ μƒν˜Έκ°„ 이동 λΆˆκ°€!
# 0λΆ€ν„° μ‹œμž‘ν•΄μ„œ 2씩증가 + 1λΆ€ν„° μ‹œμž‘ν•΄μ„œ 2씩증가
ans = 0
dfs(0, 0) # 0λΆ€ν„° 2μ”© 증가
t = ans
ans = 0
dfs(1, 0) # 1λΆ€ν„° 2μ”© 증가
print(ans+t)
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@
| 55μ°¨μ‹œ | 2023.05.18 | μœ λ‹ˆμ˜¨ νŒŒμΈλ“œ | <a href="https://www.acmicpc.net/problem/4195">친ꡬ λ„€νŠΈμ›Œν¬</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189
| 56μ°¨μ‹œ | 2023.05.18 | BFS | <a href="https://www.acmicpc.net/problem/17836">κ³΅μ£Όλ‹˜μ„ ꡬ해라!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/193
| 57μ°¨μ‹œ | 2023.05.26 | λΆ„ν•  정볡 | <a href="https://www.acmicpc.net/problem/2263">트리의 순회</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/197
| 58μ°¨μ‹œ | 2023.05.30 | λ°±νŠΈλž˜ν‚Ή | <a href="https://www.acmicpc.net/problem/1799">λΉ„μˆ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/204
---

0 comments on commit 5aee288

Please sign in to comment.