๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm๐Ÿฐ96

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ 2021 ์นด์นด์˜ค ์ธํ„ด์‹ญ DFS ๋ฌธ์ œ : https://programmers.co.kr/learn/courses/30/lessons/81302 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ [["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]] [1, 0, 1, 1, 1] programmers.co.kr ๋ถ„์„ : ํฌ๊ธฐ๋Š” 5X5 ๋ฐฐ์—ด ์˜ˆ๋ฅผ ๋“ค์–ด ์ž…๋ ฅ์ด 2์ฐจ์› ๋ฐฐ์—ด๋กœ ์ฃผ์–ด์งˆ ๋•Œ P๋Š” ์‚ฌ๋žŒ.. 2021. 9. 5.
[๋ฐฑ์ค€] 1463 1๋กœ ๋งŒ๋“ค๊ธฐ DP ๋ฌธ์ œ : https://www.acmicpc.net/problem/1463 1463๋ฒˆ: 1๋กœ ๋งŒ๋“ค๊ธฐ ์ฒซ์งธ ์ค„์— 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 106๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ๋ถ„์„ : ์žฌ๊ท€์™€ ๋ฉ”๋ชจ์ œ์ด์…˜์„ ์ด์šฉํ•ด ํ’€์—ˆ๋‹ค. ์ฒ˜์Œ์— if (d[n] > 0) return d[n]; ๋ถ€๋ถ„์„ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์•„ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋‚ฌ์—ˆ๊ณ  d[1]์ผ๋•Œ n == 1์ผ๋•Œ ์ฒ˜๋ฆฌ๋ฅผ return 0์œผ๋กœ ์ฒ˜๋ฆฌ ํ•ด์ฃผ์ง€ ์•Š์•„ 100ํผ์—์„œ ์—๋Ÿฌ๋กœ ํ—ค๋งธ๋‹ค c++ ์ฝ”๋“œ : // // 1463_makeOne.cpp // SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป // // Created by JoSoJeong on 2021/08/23. // #include #include #include using namespace std; int d[10000.. 2021. 8. 23.
[๋ฆฌํŠธ์ฝ”๋“œ] 98. Validate Binary Search Tree - BT ๋ฌธ์ œ : https://leetcode.com/problems/validate-binary-search-tree/ Validate Binary Search Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์˜ˆ์‹œ : Input: root = [5,1,4,null,null,3,6] Output: false Explanation: The root node's value is 5 but its right child's value is 4. ์ฃผ์–ด์ง„ input์ด .. 2021. 8. 17.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ณด์„ ์‡ผํ•‘ 2020 ์นด์นด์˜ค ์ธํ„ด์‰ฝ ๋ฌธ์ œ : https://programmers.co.kr/learn/courses/30/lessons/67258 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ณด์„ ์‡ผํ•‘ ["DIA", "RUBY", "RUBY", "DIA", "DIA", "EMERALD", "SAPPHIRE", "DIA"] [3, 7] programmers.co.kr ๋ถ„์„ : leetcode์— minimun window subString ๋ฌธ์ œ๋ฅผ ํ’€๊ณ  ๋‚˜์„œ ๋‹ค์‹œ ํ’€์—ˆ๋‹ค! ํˆฌํฌ์ธํ„ฐ๋กœ ์ ‘๊ทผํ–ˆ์ง€๋งŒ ๋ฐฉ๋ฒ•์„ ๋ชจ๋ฅด๊ฒ ์œผ๋‹ˆ ํ•˜๋“œ ์ฝ”๋”ฉํ™” ๋˜์–ด ๊ฐ€๋Š” ๊ฒƒ๋งŒ ๊ฐ™์•„์„œ .. TC๋„ ํ†ต๊ณผ๋„ ๋ชปํ•˜๊ณ  ์žˆ์—ˆ๋˜ ์ฐฐ๋‚˜ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ๊ด€๋ จ๋œ ๋ฌธ์ œ๋ฅผ ํ’€๊ณ ๋‚˜์„œ ๋‹ค์‹œ ์ ์šฉํ•ด๋ณด์•˜๋‹ค. c++ ์ฝ”๋“œ : // // [KAKAO] 2020_jewerly_re.cpp // SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป // // Crea.. 2021. 8. 5.
[๋ฆฌํŠธ์ฝ”๋“œ] 76. Minimum Window Substring (์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ) ๋ฌธ์ œ : https://leetcode.com/problems/minimum-window-substring/ Minimum Window Substring - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ๋‚œ์ด๋„ : hard ํ’€์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ : sliding window(์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ) โญ๏ธ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ๋ž€ ? ์ผ์ • ๋ฒ”์œ„ ๋งŒํผ์˜ ์œˆ๋„์šฐ(w)๋ฅผ ๊ฐ€์ง€๊ณ  ์Šฌ๋ผ์ด๋”ฉ ~ ํ•˜๋ฉฐ ์ฐพ๋Š” ๊ธฐ๋ฒ•์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ๊ตฌ๊ฐ„ ๋ฌธ์ œ์— ๋งŽ์ด ์‚ฌ์šฉ๋˜๋ฉฐ ํˆฌํฌ์ธํ„ฐ์™€ ๋ฐฉ๋ฒ•๋ก ์ด ๋น„์Šทํ•˜์—ฌ ๊ฐ™์ด ์–˜๊ธฐ .. 2021. 8. 5.
[๋ฆฌํŠธ์ฝ”๋“œ] 3. Longest Substring Without Repeating Characters ๋ฌธ์ œ : https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ๋‚œ์ด๋„ : Medium ํ’€์ด ๋ฐฉ๋ฒ• : ๋ธŒ๋ฃจํŠธ ํฌ์Šค O(n^2) ๋ฌธ์ž์—ด s์—์„œ ์ค‘๋ณต๋˜๋Š” ๋ฌธ์ž ์—†์ด ๊ฐ€์žฅ ๊ธด ์„œ๋ธŒ ์ŠคํŠธ๋ง์„ ์ฐพ๋Š” ๋ฌธ์ œ์˜€๋‹ค. ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด O(n) ๋งŒํผ์œผ.. 2021. 7. 16.
[๋ฆฌํŠธ์ฝ”๋“œ] 1. Two Sum (๋‘์ˆ˜์˜ ํ•ฉ) ๋ฌธ์ œ : https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ๋‚œ์ด๋„ : easy ํ’€์ด ๋ฐฉ๋ฒ• : ๋ถ€๋ฅดํŠธํฌ์Šค O(n^2) c++ ์ฝ”๋“œ : class Solution { public: vector twoSum(vector& nums, int target) { vector answer; for(int i = 0; i < nums.size(); i++){ for(int j = i + 1; .. 2021. 7. 12.
[๋ฐฑ์ค€] 5567 ๊ฒฐํ˜ผ์‹ ๊ตฌํ˜„ ๋ฌธ์ œ : https://www.acmicpc.net/problem/5567 5567๋ฒˆ: ๊ฒฐํ˜ผ์‹ 2์™€ 3์€ ์ƒ๊ทผ์ด์˜ ์นœ๊ตฌ์ด๋‹ค. ๋˜, 3๊ณผ 4๋Š” ์นœ๊ตฌ์ด๊ธฐ ๋•Œ๋ฌธ์—, 4๋Š” ์ƒ๊ทผ์ด์˜ ์นœ๊ตฌ์˜ ์นœ๊ตฌ์ด๋‹ค. 5์™€ 6์€ ์นœ๊ตฌ๋„ ์•„๋‹ˆ๊ณ , ์นœ๊ตฌ์˜ ์นœ๊ตฌ๋„ ์•„๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 2,3,4 3๋ช…์˜ ์นœ๊ตฌ๋ฅผ ๊ฒฐํ˜ผ์‹์— ์ดˆ๋Œ€ํ•œ๋‹ค. www.acmicpc.net ๋ถ„์„ : ๊ฒฐํ˜ผ์‹์— ์˜ฌ ๋™๊ธฐ๋“ค ์ค‘ ๋‚ด ์นœ๊ตฌ, ๋‚ด ์นœ๊ตฌ์˜ ์นœ๊ตฌ๋งŒ ์ดˆ๋Œ€ ํ•˜๋ ค๋ฉด ๋ช‡๋ช… ์ดˆ๋Œ€ ํ•ด์•ผ ๋ฌป๋Š” ๋ฌธ์ œ์˜€๋‹ค. ์นœ๊ตฌ ๊ด€๊ณ„๋ฅผ friends vector์— ๋„ฃ์–ด friends[์นœ๊ตฌ] = ["์นœ๊ตฌ์˜ ์นœ๊ตฌ๋“ค ๋ฆฌ์ŠคํŠธ"] ๋ฅผ ์ฐพ์œผ๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ง€๋งŒ * ์ฃผ์˜ ํ•ด์•ผ ํ•  ์ ์ด ์žˆ๋‹ค. ์นœ๊ตฌ์˜ ์นœ๊ตฌ๊ฐ€ ๋‚ด ์นœ๊ตฌ์ผ ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ ์šฐ์„  ๋‚ด ์นœ๊ตฌ๋“ค๋งŒ queue์— ๋„ฃ์–ด result ๊ฐ’์„ ์ฆ๊ฐ€์‹œ์ผœ์ค€ ๋‹ค์Œ que.. 2021. 6. 13.
[๋ฐฑ์ค€] 2579 ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ DP ๋ฌธ์ œ : https://www.acmicpc.net/problem/2579 2579๋ฒˆ: ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ ๊ฒŒ์ž„์€ ๊ณ„๋‹จ ์•„๋ž˜ ์‹œ์ž‘์ ๋ถ€ํ„ฐ ๊ณ„๋‹จ ๊ผญ๋Œ€๊ธฐ์— ์œ„์น˜ํ•œ ๋„์ฐฉ์ ๊นŒ์ง€ ๊ฐ€๋Š” ๊ฒŒ์ž„์ด๋‹ค. ๊ณผ ๊ฐ™์ด ๊ฐ๊ฐ์˜ ๊ณ„๋‹จ์—๋Š” ์ผ์ •ํ•œ ์ ์ˆ˜๊ฐ€ ์“ฐ์—ฌ ์žˆ๋Š”๋ฐ ๊ณ„๋‹จ์„ ๋ฐŸ์œผ๋ฉด ๊ทธ ๊ณ„๋‹จ์— ์“ฐ์—ฌ ์žˆ๋Š” ์  www.acmicpc.net ๋ถ„์„ : ๊ณ„๋‹จ์ด ์žˆ์„ ์‹œ ๊ณ„๋‹จ์„ ์˜ค๋ฅด๋Š”๋ฐ ๊ทœ์น™์ด ์žˆ๋‹ค --> ์ ํ™”์‹์ด๊ตฐ ๊ณ„๋‹จ์€ ํ•œ ๋ฒˆ์— ํ•œ ๊ณ„๋‹จ์”ฉ ๋˜๋Š” ๋‘ ๊ณ„๋‹จ์”ฉ ์˜ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, ํ•œ ๊ณ„๋‹จ์„ ๋ฐŸ์œผ๋ฉด์„œ ์ด์–ด์„œ ๋‹ค์Œ ๊ณ„๋‹จ์ด๋‚˜, ๋‹ค์Œ ๋‹ค์Œ ๊ณ„๋‹จ์œผ๋กœ ์˜ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. ์—ฐ์†๋œ ์„ธ ๊ฐœ์˜ ๊ณ„๋‹จ์„ ๋ชจ๋‘ ๋ฐŸ์•„์„œ๋Š” ์•ˆ ๋œ๋‹ค. ๋‹จ, ์‹œ์ž‘์ ์€ ๊ณ„๋‹จ์— ํฌํ•จ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋งˆ์ง€๋ง‰ ๋„์ฐฉ ๊ณ„๋‹จ์€ ๋ฐ˜๋“œ์‹œ ๋ฐŸ์•„์•ผ ํ•œ๋‹ค. stairArr [i] = i๋ฒˆ์งธ ๊ณ„๋‹จ์˜ ๊ฐ’ d [i] = .. 2021. 6. 13.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Summer/Winter Coding ์Šคํ‚ฌํŠธ๋ฆฌ level2 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/49993 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์Šคํ‚ฌํŠธ๋ฆฌ programmers.co.kr ๋ถ„์„ : ๋ถ„๋ช… ๋‚˜๋ณด๋‹ค ๋” ํšจ์œจ์ ์ธ ์ฝ”๋“œ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•œ๋‹ค! ํ•˜์ง€๋งŒ ์ด ๋ฌธ์ œ๋Š” ๋‹คํ–‰ํžˆ(?) ํšจ์œจ์„ฑ ์ฒดํฌํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ์•„๋‹ˆ์—ฌ์„œ ๋งž์ถœ ์ˆ˜ ์žˆ์—ˆ๋‹ค. (soma ์ฒซ ๊ฒŒ์ž„ ๋ฌธ์ œ์™€ ๋น„์Šทํ•œ ์œ ํ˜•์˜ ๋ฌธ์ œ๋ผ(๊ทผ๋ฐ ๊ทธ ์นœ๊ตฌ๋Š” ์œ„์ƒ ์ •๋ ฌ์ด์—ˆ๋‹ค) ๊ผญ ํ’€๊ณ  ์‹ถ์—ˆ๋‹ค) ์ด ๋ฌธ์ œ๋Š” ์ „์— ์ตœ์žฅ ๊ณตํ†ต ๋ถ€๋ถ„ ์ˆ˜์—ด ๊ณต๋ถ€ํ–ˆ์„๋•Œ ์–ธ๋œป ๋ดค์—ˆ๋˜ ์ตœ์žฅ ๊ณตํ†ต ๋ถ€๋ถ„ ๋ฌธ์ž์—ด๊ณผ ๋น„์Šทํ•ด ๋ณด์ด์ง€๋งŒ skill์˜ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ์Šคํ‚ฌ ํŠธ๋ฆฌ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ์ ์—์„œ ์กฐ๊ธˆ ๋‹ค๋ฅด๋‹ค. ๋งŒ์•ฝ์— ์ œ์‹œ๋œ skill ์ˆœ์„œ๊ฐ€ CBD ์ด๊ณ  ์ˆœ์„œ์— ๋งž๋Š”์ง€ ๊ฒ€์‚ฌํ•˜๊ณ  ์‹ถ์€ ๋Œ€์ƒ๋“ค {"CBADF", " AECB", "OP.. 2021. 5. 8.
[๋ฐฑ์ค€] 1149 RGB ๊ฑฐ๋ฆฌ DP ใ…‡๋ฌธ์ œ : www.acmicpc.net/problem/1149 1149๋ฒˆ: RGB๊ฑฐ๋ฆฌ ์ฒซ์งธ ์ค„์— ์ง‘์˜ ์ˆ˜ N(2 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ ์ง‘์„ ๋นจ๊ฐ•, ์ดˆ๋ก, ํŒŒ๋ž‘์œผ๋กœ ์น ํ•˜๋Š” ๋น„์šฉ์ด 1๋ฒˆ ์ง‘๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ง‘์„ ์น ํ•˜๋Š” ๋น„์šฉ์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ www.acmicpc.net ๋ถ„์„ : rgb ์ƒ‰๊น”์„ ์–‘ ์˜† ์ง‘๋งˆ๋‹ค ๊ฒน์น˜์ง€ ์•Š๊ฒŒ ์ƒ‰์น ํ•˜๋Š”๋ฐ ๊ทธ ์ตœ์†Œ ๋น„์šฉ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ๋‹ค. dp ๋ฐฐ์—ด์€ 2์ฐจ์› ๋ฐฐ์—ด๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ dp[i][0], dp[i][1], dp[i][2]๋Š” ๊ฐ๊ฐ i๋ฒˆ์งธ ์ง‘๊นŒ์ง€ ์ƒ‰์น ํ• ๋•Œ 0-๋นจ๊ฐ„์ƒ‰ ์ตœ์†Œ ๋น„์šฉ,1-๋…ธ๋ž€์ƒ‰ ์ตœ์†Œ ๋น„์šฉ,2-ํŒŒ๋ž€์ƒ‰ ์ตœ์†Œ ๋น„์šฉ์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๋ฐฐ์—ด์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด dp[1][1]์€ ์ด์ „ 0๋ฒˆ์งธ ์ง‘์„ ์ƒ‰์น ํ• ๋•Œ ๋“œ๋Š” ์ตœ์†Œ ๋น„์šฉ์—.. 2021. 5. 8.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ฒฝ์ฃผ๋กœ ๊ฑด์„ค 2020 ์นด์นด์˜ค ์ธํ„ด์‰ฝ level3 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/67259 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ฒฝ์ฃผ๋กœ ๊ฑด์„ค [[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0],[0,0,0,0,0,1,0,0],[0,0,0,0,1,0,0,0],[0,0,0,1,0,0,0,1],[0,0,1,0,0,0,1,0],[0,1,0,0,0,1,0,0],[1,0,0,0,0,0,0,0]] 3800 [[0,0,1,0],[0,0,0,0],[0,1,0,1],[1,0,0,0]] 2100 [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,0,1,0,0,0],[1,0,0,1,0,1],[ programmers.co.kr ๋ถ„์„ : ์ด ๋ฌธ์ œ๋Š” ๋ฐฑ์ค€์—์„œ ํ’€์—ˆ๋˜ ๋‚ด๋ฆฌ๋ง‰๊ธธ ๋ฌธ์ œ์™€ ๋น„์Šทํ•˜๊ฒŒ dp + dfs์˜ ์กฐํ•ฉ๋ฌธ์ œ์˜€๋‹ค... 2021. 5. 7.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Summer/Winder Coding ๊ธฐ์ง€๊ตญ ์„ค์น˜ level3 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/12979 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ธฐ์ง€๊ตญ ์„ค์น˜ N๊ฐœ์˜ ์•„ํŒŒํŠธ๊ฐ€ ์ผ๋ ฌ๋กœ ์ญ‰ ๋Š˜์–ด์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ค‘์—์„œ ์ผ๋ถ€ ์•„ํŒŒํŠธ ์˜ฅ์ƒ์—๋Š” 4g ๊ธฐ์ง€๊ตญ์ด ์„ค์น˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ์ˆ ์ด ๋ฐœ์ „ํ•ด 5g ์ˆ˜์š”๊ฐ€ ๋†’์•„์ ธ 4g ๊ธฐ์ง€๊ตญ์„ 5g ๊ธฐ์ง€๊ตญ์œผ๋กœ ๋ฐ”๊พธ๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ 5 programmers.co.kr ๋ถ„์„ : ์‹œ๊ฐ„์ดˆ๊ณผ + ์—๋Ÿฌ๋‚œ c++ ์ฝ”๋“œ : // // [SW] 2018_BaseStation.cpp // SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป // // Created by JoSoJeong on 2021/05/06. // #include #include #include #include #include using namespace std; //vector statio.. 2021. 5. 6.
[๋ฐฑ์ค€] 16236 ์•„๊ธฐ ์ƒ์–ด DFS, Priority-Queue ๋ฌธ์ œ : www.acmicpc.net/problem/16236 16236๋ฒˆ: ์•„๊ธฐ ์ƒ์–ด N×N ํฌ๊ธฐ์˜ ๊ณต๊ฐ„์— ๋ฌผ๊ณ ๊ธฐ M๋งˆ๋ฆฌ์™€ ์•„๊ธฐ ์ƒ์–ด 1๋งˆ๋ฆฌ๊ฐ€ ์žˆ๋‹ค. ๊ณต๊ฐ„์€ 1×1 ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜• ์นธ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋‹ค. ํ•œ ์นธ์—๋Š” ๋ฌผ๊ณ ๊ธฐ๊ฐ€ ์ตœ๋Œ€ 1๋งˆ๋ฆฌ ์กด์žฌํ•œ๋‹ค. ์•„๊ธฐ ์ƒ์–ด์™€ ๋ฌผ๊ณ ๊ธฐ๋Š” ๋ชจ๋‘ ํฌ๊ธฐ๋ฅผ ๊ฐ€ www.acmicpc.net ๋ฌธ์ œ ์„ค๋ช… : -> ์•„๊ธฐ ์ƒ์–ด๊ฐ€ ๋ช‡์ดˆ ๋™์•ˆ ๋ฌผ๊ณ ๊ธฐ ์žก์•„๋จน์„ ์ˆ˜ ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•˜์‹œ์˜ค ๊ณต๊ฐ„ n = 4 0: ๋นˆ ์นธ 1, 2, 3, 4, 5, 6: ์นธ์— ์žˆ๋Š” ๋ฌผ๊ณ ๊ธฐ์˜ ํฌ๊ธฐ 9: ์•„๊ธฐ ์ƒ์–ด์˜ ์œ„์น˜ ์•„๊ธฐ ์ƒ์–ด๊ฐ€ ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ์กฐ๊ฑด 1. ์ž๊ธฐ ์ฃผ๋ณ€์— ์ธ์ ‘ํ•œ ๋ฌผ๊ณ ๊ธฐ && ๋จน์„ ์ˆ˜ ์žˆ๋‹ค๋ฉด ๊ฐ€์žฅ ์ธ์ ‘ํ•œ ๋ฌผ๊ณ ๊ธฐ๋ฅผ ๋จน์œผ๋Ÿฌ ๊ฐ„๋‹ค. 2. ์ธ์ ‘ํ•œ ๋ฌผ๊ณ ๊ธฐ๊ฐ€ ์—ฌ๋Ÿฌ ๋งˆ๋ฆฌ๋ผ๋ฉด ๊ฐ€์žฅ ์œ„์— ์žˆ๋Š” ๋ฌผ๊ณ ๊ธฐ, ๊ฐ€์žฅ ์™ผ์ชฝ์— ์žˆ๋Š” ๋ฌผ๊ณ ๊ธฐ.. 2021. 5. 6.
[๋ฐฑ์ค€] 9095 1,2,3 ๋”ํ•˜๊ธฐ DP ๋ฌธ์ œ : www.acmicpc.net/problem/9095 9095๋ฒˆ: 1, 2, 3 ๋”ํ•˜๊ธฐ ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค, n์„ 1, 2, 3์˜ ํ•ฉ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ๋ถ„์„ : ์ ํ™”์‹์„ ์„ธ์šฐ๋ฉด ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€๋‹ค! ํฐ ๋ฌธ์ œ๊ฐ€ ์ž‘์€ ๋ฌธ์ œ๋กœ ๋‚˜๋ˆ„์–ด์ง€๋Š” ์ „ํ˜•์ ์ธ dp ๋ฌธ์ œ์˜€๊ณ  1, 2, 3์˜ ํ•ฉ์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค๋Š” ๊ฒƒ์€ 1์ผ๋•Œ 1 2์ผ๋•Œ 1 + 1 2 3์ผ๋•Œ 1 + 1 + 1 1 + 1 + 2 1 + 2 + 1 1 + 1 + 2 1 + 3 ๊ณผ ๊ฐ™์ด ๋‚˜ํƒ€๋‚ด์–ด์ง€๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. n = 4์ผ ๊ฒฝ์šฐ ๋‚˜ํƒ€๋‚ด์–ด์ง€๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ memo[4]๋ผ๊ณ  ํ•˜์ž ๊ทธ๋Ÿด๋•Œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” 1 + memo[3] 2 + memo[2] 3 + memo[1] ์ผ ๊ฒƒ์ด๋‹ค. ๋”ฐ๋ผ์„œ ์ ํ™”์‹์€ memo[n.. 2021. 5. 4.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Summer/Winter Coding ์ง€ํ˜• ์ด๋™ level 4 MST ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/62050 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ง€ํ˜• ์ด๋™ [[1, 4, 8, 10], [5, 5, 5, 5], [10, 10, 10, 10], [10, 10, 10, 20]] 3 15 [[10, 11, 10, 11], [2, 21, 20, 10], [1, 20, 21, 11], [2, 1, 2, 1]] 1 18 programmers.co.kr ๋ถ„์„ : ๋ฌธ์ œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๋˜๋Š” ์‹์ด์—ˆ๋‹ค. ํฌ๋ฃจ์Šค์นผ ์•Œ๊ณ ๋ฆฌ์ฆ˜, spanning tree ์ฒ˜์Œ ๊ณต๋ถ€ํ•ด๋ณด๋Š”๋ฐ ๋ฐฑ์ค€์—์„œ ์œ ์ œ ๋ฌธ์ œ๋ฅผ ๋” ํ’€์–ด๋ด์•ผ๊ฒ ๋‹ค. c++ ์ฝ”๋“œ : // // [SW] 2019_terrainMove.cpp // SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป // // Created by JoSoJeong on 202.. 2021. 5. 2.
[๋ฐฑ์ค€] 1937 ์š•์‹ฌ์Ÿ์ด ํŒ๋‹ค ๐Ÿผ DP ๋ฌธ์ œ : www.acmicpc.net/problem/1937 1937๋ฒˆ: ์š•์‹ฌ์Ÿ์ด ํŒ๋‹ค n*n์˜ ํฌ๊ธฐ์˜ ๋Œ€๋‚˜๋ฌด ์ˆฒ์ด ์žˆ๋‹ค. ์š•์‹ฌ์Ÿ์ด ํŒ๋‹ค๋Š” ์–ด๋–ค ์ง€์—ญ์—์„œ ๋Œ€๋‚˜๋ฌด๋ฅผ ๋จน๊ธฐ ์‹œ์ž‘ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ๊ณณ์˜ ๋Œ€๋‚˜๋ฌด๋ฅผ ๋‹ค ๋จน์–ด ์น˜์šฐ๋ฉด ์ƒ, ํ•˜, ์ขŒ, ์šฐ ์ค‘ ํ•œ ๊ณณ์œผ๋กœ ์ด๋™์„ ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋˜ ๊ทธ๊ณณ์—์„œ www.acmicpc.net ๋ถ„์„ : n x n ํŒ๋‹ค ์ง‘์ด ์žˆ์œผ๋ฉด ํŒ๋‹ค๋Š” ์ƒํ•˜ ์ขŒ์šฐ๋กœ ์›€์ง์ผ ์ˆ˜ ์žˆ๊ณ  ํ˜„ ์œ„์น˜์—์„œ ๋‹ค์Œ ๋‚ ์ด ๋ ๋•Œ ์ด๋™ํ•˜๋Š”๋ฐ ์ด๋™ํ•˜๋Š” ์นธ์— ๋จน์ด๊ฐ€ ๋” ๋งŽ์•„์•ผ ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ์š•์‹ฌ์Ÿ์ด ์นœ๊ตฌ๋‹ค. ๊ทธ๋ž˜์„œ ์ตœ๋Œ€๋กœ ์‚ด ์ˆ˜ (?) ์žˆ๊ฒŒ ํ•˜๋Š” ๋‚ ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค. arr๋ฐฐ์—ด์— ๋ฐฅ์„ ๋„ฃ์–ด์ฃผ๊ณ  dp๋ฅผ ๋™์‹œ์— 0์œผ๋กœ ์ดˆ๊ธฐํ™” ์‹œ์ผœ์ค€ ๋’ค dp ํ•จ์ˆ˜๋ฅผ ๋Œ๋ฉด์„œ ์ตœ๋Œ€๋กœ ์‚ด ์ˆ˜ ์žˆ๋Š” maxRice (maxLife ๋ณ€์ˆ˜๊ฐ€ ๋” ์ ์ ˆํ• ๋“ฏ.. 2021. 5. 2.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ•ฉ์Šน ํƒ์‹œ ์š”๊ธˆ 2021 ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ํ…Œ์ŠคํŠธ level3 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/72413 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ•ฉ์Šน ํƒ์‹œ ์š”๊ธˆ 6 4 6 2 [[4, 1, 10], [3, 5, 24], [5, 6, 2], [3, 1, 41], [5, 1, 24], [4, 6, 50], [2, 4, 66], [2, 3, 22], [1, 6, 25]] 82 7 3 4 1 [[5, 7, 9], [4, 6, 4], [3, 6, 1], [3, 2, 3], [2, 1, 6]] 14 6 4 5 6 [[2,6,6], [6,3,7], [4,6,7], [6,5,11], [2,5,12], [5,3,20], [2,4 programmers.co.kr ๋ถ„์„ : ์ฒซ๋ฒˆ์งธ ์ ‘๊ทผ ๋ฌธ์ œ๋ฅผ ๋ณด์•„ํ•˜๋‹ˆ a์™€ b๊ฐ€ ๋”ฐ๋กœ ๊ฐ”์„๋•Œ์™€ ์ค‘๊ฐ„ ์ง€์  ๊ฑธ์ณ์„œ ๋„์ฐฉํ•œ .. 2021. 5. 2.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Summer/Winder coding ๋ฐฉ๋ฌธ ๊ธธ์ด level2 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/49994 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฐฉ๋ฌธ ๊ธธ์ด programmers.co.kr ๋ถ„์„ : ์ฒ˜์Œ์— dfs๋ฌธ์ œ์ธ์ค„ ์•Œ๊ณ  ๋งˆ์นจ ์˜ค๋Š˜ dfs ์Šคํ„ฐ๋”” ํ•ด์„œ dfs ์งœ๋‹ค๊ฐ€ stack์— push ํ•ด์ค„ ํ•„์š”๊ฐ€ ์—†์Œ์„ ๋Š๋ผ๊ณ  ๋‹จ์ˆœ ๋ฌธ์ž์—ด ๊ธธ์ด๋งŒํผ for๋ฌธ์„ ๋Œ์•„ answer ๊ฐ’์„ ์ฆ๊ฐ€ ํ•ด์ฃผ๋Š” ์‹์œผ๋กœ ๊ฐ„์†Œํ™” ํ•˜์˜€๋‹ค. 1. ์ฒซ ์ ‘๊ทผ ๋ฐฉ์‹ ๊ฐ”๋˜ ๊ฐ„์„ ์€ ๋˜ ๊ฐˆ ์ˆ˜ ์—†์œผ๋‹ˆ 2์ฐจ์› visit ๋ฐฐ์—ด ์ƒ์„ฑ ํ›„ false์ธ ์ขŒํ‘œ์— ๋Œ€ํ•ด์„œ๋งŒ answer ๊ฐ’ ์ฆ๊ฐ€์‹œํ‚ค๊ธฐ ํ•˜์ง€๋งŒ ์ด ๋ฐฉ์‹์€ 1๋ฒˆ์‹œ, ๋„์ฐฉ ๋…ธ๋“œ๋กœ ๋ฐฉ๋ฌธํ–ˆ๋˜ (5,6)๋ฒˆ์ง€๋ฅผ 7๋ฒˆ ์ž‘์—… ์ˆ˜ํ–‰์‹œ (5,6)๋ฒˆ์ด ์ด๋ฏธ ๋ฐฉ๋ฌธํ•œ ๋…ธ๋“œ๊ฐ€ ๋˜์—ˆ์œผ๋ฏ€๋กœ 7๋ฒˆ ๊ฐ„์„ ์„ ๋งŒ๋“ค์ˆ˜ ์—†๊ฒŒ ๋œ๋‹ค. ๊ทธ๋ž˜์„œ ์ •์  ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•˜๋ฉด ์•ˆ๋œ๋‹ค.. 2021. 4. 30.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ˆœ์œ„ ๊ฒ€์ƒ‰ 2021 ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ํ…Œ์ŠคํŠธ level2 ๋ฌธ์ œ : programmers.co.kr/learn/courses/30/lessons/72412 >str){ j++; if(j == 5){ memberScore.push_back(stoi(str)); continue; } memberSet[i].insert(str); } } for(int i = 0; i >str){ j++; if(str == "and"){ continue; } if(j == 8){ searchScore.push_back(stoi(str)); continue; } searchQuery[i].push_back(str); }.. 2021. 4. 28.