Skip to content

Commit

Permalink
2024-05-30
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed May 31, 2024
1 parent 93acc1f commit 90009df
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 @@ -60,4 +60,5 @@
| 53μ°¨μ‹œ | 2024.05.09 | λ°±νŠΈλž˜ν‚Ή | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 54μ°¨μ‹œ | 2024.05.14 | λ‹€μ΅μŠ€νŠΈλΌ | <a href="https://www.acmicpc.net/problem/9370">미확인 도착지</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185
| 55μ°¨μ‹œ | 2023.05.18 | μœ λ‹ˆμ˜¨ νŒŒμΈλ“œ | <a href="https://www.acmicpc.net/problem/4195">친ꡬ λ„€νŠΈμ›Œν¬</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189
| 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 90009df

Please sign in to comment.