๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

DFS2

BOJ 5921 ) Escaping the Farm (C++) 5921๋ฒˆ: Escaping the Farm The cows have decided on a daring plan to escape from the clutches of Farmer John. They have managed to procure a small inflatable raft, and during the cover of night, a group of cows will board the raft and row across the river bordering the farm. The pla www.acmicpc.net ์†Œ๊ฐ€ 20๋งˆ๋ฆฌ๋ฐ–์— ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•ด๋„ ๋œ๋‹ค. DFS๋ฅผ ์ด์šฉํ•ด ๊ฐ ์†Œ๋ฅผ ๋ฐฐ์— ํƒœ์šธ์ง€ ๋ง์ง€๋ฅผ ๊ณ ๋ฅธ ํ›„ N๋ฒˆ์งธ ์†Œ์— ๋Œ€ํ•œ ์„ ํƒ๊นŒ์ง€ ๋๋‚˜๋ฉด ๊ฐ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ์—์„œ ์ž๋ฆฌ์˜ฌ๋ฆผ์ด .. 2022. 6. 13.
BOJ 1012 ) ์œ ๊ธฐ๋† ๋ฐฐ์ถ” 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net DFS๋กœ ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ. ์™ ์ง„ ๋ชจ๋ฅด์ง€๋งŒ ์˜ˆ์ „์— ํ’€๋ ค๊ณ  ์‹œ๋„ํ–ˆ๋‹ค๊ฐ€ ์‹คํŒจํ•œ ํ”์ ์ด ๋‚จ์•„์žˆ์—ˆ๋‹ค. ๋ฒกํ„ฐ๋ฅผ ์ด์šฉํ•ด ๋ฐญ์˜ ํฌ๊ธฐ๋ฅผ ๋Ÿฐํƒ€์ž„์— ์ง€์ •ํ•ด์ฃผ๊ณ  ๋ฐฐ์ถ”๋Š” 1๋กœ ํ‘œ์‹œํ•œ๋‹ค. ๋ฐฉ๋ฌธ์—ฌ๋ถ€๋Š” ๋ฐฐ์ถ”๊ฐ€ ์—†๋Š” ๊ณณ์€ ๋ฐฉ๋ฌธํ•  ํ•„์š”๊ฐ€ ์—†์œผ๋ฏ€๋กœ ๊ธฐ๋ณธ์€ ๋ชจ๋‘ 0์œผ๋กœ, ๋ฐฐ์ถ”๊ฐ€ ์žˆ๋Š” ๊ณณ์€ ๋ฐฐ์ถ” ์œ„์น˜๋ฅผ ํ‘œ์‹œํ•˜๋ฉด์„œ ๊ฐ™์ด ๋ฐฉ๋ฌธ์—ฌ๋ถ€๋ฅผ 1๋กœ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค. ๊ทธ ์ดํ›„์—๋Š” ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฉด์„œ ๋ฐฐ์ถ”๊ฐ€ ์‹ฌ๊ฒจ์ง„ ๊ณณ์„ dfs๋กœ ํƒ์ƒ‰ํ•œ๋‹ค. ๋‹ค์Œ ์นธ์„ ๋ฐฉ๋ฌธํ• ์ง€ ๋ง์ง€๋Š” ๋ฐฐ์ถ”๊ฐ€ ์žˆ๋Š”์ง€์™€ ๋ฐฉ๋ฌธํ•œ์ ์ด ์—†๋Š”์ง€๋ฅผ ๋ชจ๋‘ ๊ณ ๋ คํ•ด์ค€๋‹ค. #i.. 2021. 3. 12.
๋ฐ˜์‘ํ˜•