Skip to content

Conversation

@tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Feb 3, 2025

πŸ”— 문제 링크

내리막 κΈΈ

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1μ‹œκ°„

μ§„μ§œ κ·Ό 6κ°œμ›”κ°„ κ°„λ§Œμ— 문제 ν’€λ‹€κ°€ λ§‰ν˜€μ„œ 레퍼런슀 보고 ν’€μ—ˆμŠ΅λ‹ˆλ‹€..

✨ μˆ˜λ„ μ½”λ“œ

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@tgyuuAn tgyuuAn added tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. μž‘μ„± 쀑 ⏱️ labels Feb 3, 2025
@tgyuuAn tgyuuAn self-assigned this Feb 3, 2025
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜€λžœλ§Œμ— dfs 문제λ₯Ό ν’€μ–΄λ΄…λ‹ˆλ‹Ή,,
μš”λ²ˆ λ¬Έμ œλŠ” dfs에 λ©”λͺ¨λΌμ΄μ§•을 μ–΄λ–»κ²Œ ν•  것이냐...κ°€ κ΄€κ±΄μ΄μ—ˆλ˜ 것 κ°™λ„€μš”
dp + dfs 흠흠.. μ΄λ ‡κ²Œ ν•˜λ‚˜λ₯Ό 또 μ€μ€ν•΄κ°‘λ‹ˆλ“œμ•— !!!!! 🫑πŸ”₯


import sys
from collections import deque
sys.setrecursionlimit(10**6)

def input() : return sys.stdin.readline().rstrip()

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

q = deque()
visit = [[False] * M for _ in range(N)]
direc = [(0,1), (1,0), (-1,0), (0,-1)]
q.append((0,0))
dp = [[10**9] * M for _ in range(N)]

def dfs(x,y):
    if x == N-1 and y == M-1:
        return 1
    
    if visit[x][y] == True:
        return dp[x][y]
    
    dp[x][y] = 0
    visit[x][y] = True
    
    for dir_x, dir_y in direc:
        next_x = dir_x + x
        next_y = dir_y + y
        
        if next_x < 0 or next_y < 0 or next_x >= N or next_y >= M:
            continue
        
        if info[next_x][next_y] < info[x][y]:
            dp[x][y] += dfs(next_x, next_y)
            
    return dp[x][y]

print(dfs(0,0))

@tgyuuAn
Copy link
Member Author

tgyuuAn commented Feb 11, 2025

μ˜€λžœλ§Œμ— dfs 문제λ₯Ό ν’€μ–΄λ΄…λ‹ˆλ‹Ή,, μš”λ²ˆ λ¬Έμ œλŠ” dfs에 λ©”λͺ¨λΌμ΄μ§•을 μ–΄λ–»κ²Œ ν•  것이냐...κ°€ κ΄€κ±΄μ΄μ—ˆλ˜ 것 κ°™λ„€μš” dp + dfs 흠흠.. μ΄λ ‡κ²Œ ν•˜λ‚˜λ₯Ό 또 μ€μ€ν•΄κ°‘λ‹ˆλ“œμ•— !!!!! 🫑πŸ”₯

import sys
from collections import deque
sys.setrecursionlimit(10**6)

def input() : return sys.stdin.readline().rstrip()

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

q = deque()
visit = [[False] * M for _ in range(N)]
direc = [(0,1), (1,0), (-1,0), (0,-1)]
q.append((0,0))
dp = [[10**9] * M for _ in range(N)]

def dfs(x,y):
    if x == N-1 and y == M-1:
        return 1
    
    if visit[x][y] == True:
        return dp[x][y]
    
    dp[x][y] = 0
    visit[x][y] = True
    
    for dir_x, dir_y in direc:
        next_x = dir_x + x
        next_y = dir_y + y
        
        if next_x < 0 or next_y < 0 or next_x >= N or next_y >= M:
            continue
        
        if info[next_x][next_y] < info[x][y]:
            dp[x][y] += dfs(next_x, next_y)
            
    return dp[x][y]

print(dfs(0,0))

근데 이 문제 막상 λ‹€μ‹œ 풀라고 ν•˜λ©΄ μ € 아이디어가 μ•ˆλ– μ˜€λ₯Ό 것 같은데... γ… γ… γ… γ… γ… γ… γ… γ… γ… 

@tgyuuAn tgyuuAn merged commit f8f1361 into main Feb 11, 2025
6 checks passed
@tgyuuAn tgyuuAn deleted the 88-tgyuuAn branch February 11, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. 리뷰 μ™„λ£Œ βœ”οΈ

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants