-
Notifications
You must be signed in to change notification settings - Fork 0
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
7-dhlee777 #31
7-dhlee777 #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ κ°λΆν° μμ°¨μ μΌλ‘ λμ΄ν΄μ£ΌκΈ° μν΄μ μ λ ¬μ νκ³ νλμ© λ°©λ¬Έν΄κ°λ©΄μ κΈ°μ‘΄μ λ°©λ¬Ένλμ§ μ¬λΆλ₯Ό 체ν¬νλ©΄μ μ¬κ·μ μΌλ‘ μ μ‘μμ£Όμλ κ² κ°μ΅λλ€!
λ΅μ κ°μλ N!λ‘ μ¬κΈ°μλ μ΅λ 8κ°μ μμλ₯Ό κ°μ§κ³ μ§ννμμ΅λλ€. κ·ΈλΌ μ΅λ κ°μλ 8!λ‘ 40,320λ²μ μ°μ°μ μ€ννκ² κ΅°μ?
λ§μ½ 100κ° μ΄μμΌλ‘ μ§νλλ€λ©΄ μ΄λ€ λ°©μμΌλ‘ μ κ·Όν΄μ νμ΄μΌλ κΉμ?
μ€μ° 그건 μ λ μ΄λ €μΈ κ² κ°μλ°μ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ νμ΄λ΄€λ λ¬Έμ κΈΈλ μ μ½λλ λΉκ΅νλ €κ³ λ΄€λλ μ μ½λλ μμ λΉμ·ν΄μ λλμ΅λλ€! κΉλνκ² DFSλ‘ μ ν΄κ²°νμ κ² κ°μμ!
dfs ν¨μμ int vt νλΌλ―Έν°λ κ²°κ΅ λκΉμ§ μ¬μ©λμ§ μμκ΅°μ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ΄μ΄λΌ 벑ν°μ μ μ₯νμ¬ λ°©λ¬Έμ¬λΆλ₯Ό 체ν¬νκ΅°μ γ γ μ λ μ μ°λμ΄ λ§μνμ μκ° μμ² μ»€μ‘μ λ μ΄λ€ λ°©λ²μ μ¬μ©ν΄μΌνλμ§ κ°μκΈ° κΆκΈν΄μ‘λ€μ λ¨Όκ° dpμΌ κ² κ°κΈ°λ νκ³ .. νΌμ μ λ΄€μ΅λλ€
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/15654
βοΈ μμλ μκ°
3μκ°
β¨ μλ μ½λ
nκ°μμ
μ€μmκ°μ μ
λ₯Ό 골λΌμμ΄
μ λ§λλ λ¬Έμ μ΄λ€.μ‘°ν©
μ κ²½μ°μλ μμκ° μκ΄μμΌλ―λ‘visited μ¬λΆ
λ§ νμΈν΄μ€ λ€μ μΆλ ₯ν΄μ£Όλ©΄ λμ§λ§μμ΄
μ μμκ° μκΈ°μvector
μλ°©λ¬Έμμλλ‘
μλ₯Ό λ£μ΄μ€λ€μ μΆλ ₯ν΄μ€λ€. μ΄ λ¬Έμ μμ μ£Όμν μ μμ«μκ° μ λ ¬μ΄μλμν
μ΄λ―λ‘ μ«μλ₯Όμ€λ¦μ°¨μμΌλ‘ μ λ ¬
νλ€ νμμ μ§νν΄μ€λ€.λ©μΈμ½λ
1.μ 체μμ κ°μ
num_size
, λ½μ μμ κ°μpicked_size
λ₯Όμ λ ₯λ°λλ€2.forλ¬Έμ ν΅ν΄
numλ°°μ΄
λ‘num_size
λ§νΌ μλ€μ μ λ ₯λ°λλ€.3.μ λ ₯λ°μ μλ€μ λ€μ£½λ°μ£½μ΄λ―λ‘
μ¬μ μ μ λ ¬
μμν΄sortν¨μ
λ₯Ό ν΅ν΄numλ°°μ΄
μμ€λ¦μ°¨μμ λ ¬
μ ν΄μ€λ€.4.0λ²μ¨°μ«μλΆν° dfsμ§ν
bfsμ½λ
1.
for문
μ ν΅ν΄ λ°©λ¬Ένμ§ μμμ μ μΌλ‘ νμμ μ§νν΄μ€λ€.2.νμμ μ±κ³΅νλ©΄
visited[]=true
λ‘ λ°©λ¬Ένμλ₯Ό νκ³ νμν μλ₯Ό 벑ν°μ λ£μ΄μ€λ€.(μμκ°μλμμ΄
μ΄κΈ°μ μ°¨λ‘λλ‘ λ²‘ν°μ λ£μ΄μ€λ€.)2.λ½μμΌνλ μ«μλ§νΌ νμμ λ€ ν΄μ€κ²½μ° 벑ν°μ μλ λ°©λ¬Έν μλ₯Ό
μμλλ‘
μΆλ ₯ν΄μ€λ€(μμ΄ μΆλ ₯)3.νμμ μλ£νν λ€λ₯Έ νμμ μν΄
v.pop_bakc()
μΌλ‘ μλ₯Ό νλ λΉΌμ£Όκ³visited[]=false
λ‘ λ°κΏμ€λ€.π μλ‘κ² μκ²λ λ΄μ©
dfs
μμ맀κ°λ³μλ₯Ό cnt,vt
λκ°λ₯Ό λμμ§λ§ νκ³ λμ 보λcnt
λ§ μμ΄λ μκ΄μλ€λ κ²μ κΉ¨λ¬μλ€. νμ§λ§ νμ¬ μ΄λ μ μ μμλμ§ μ§κ΄μ μΌλ‘ λ³Ό μ μμλ€.