[Baekjoon] 12920 – 평범한 배낭2

📖 문제 이해하기 이 문제는 고전적인 배낭(Knapsack) 문제의 변형입니다. 민호는 캠프에 가기 위해 가방을 싸려고 하는데, 각 물건은 무게와 만족도를 가지고 있습니다. 일반적인 배낭 문제와 다른 점은, 같은 물건을 여러 개 넣을 수 있다는 것입니다. 단, 각 물건은 최대 K개까지만 존재합니다. 예를 들어, 무게 3kg, 만족도 4인 물건이 5개 있고, 가방의 최대 무게가 10kg이라면, 우리는…

[Baekjoon] 11266 – 단절점

📖 문제 해석 이 문제는 무방향 그래프에서 모든 단절점을 찾아 오름차순으로 출력하는 것입니다. 예를 들어, 5개의 정점이 있는 그래프에서 정점 1이 정점 2, 3과 연결되고, 정점 2가 정점 4, 5와 연결된 상황을 생각해봅시다. 만약 정점 2를 제거한다면 {1, 3}과 {4, 5}라는 두 개의 분리된 성분이 만들어지므로, 정점 2는 단절점이 됩니다. 주목할 점은 입력 그래프가 반드시…

[Baekjoon] 2887 – 행성 터널

📖 문제 이해하기 이 문제는 N개의 행성을 최소 비용으로 모두 연결하는 터널 네트워크를 구축하는 것입니다. 각 행성은 3차원 공간의 한 점으로 표현되며, 두 행성 사이의 터널 건설 비용은 특별한 방식으로 계산됩니다. 두 행성 A(xA, yA, zA)와 B(xB, yB, zB) 사이의 비용은 min(|x<sub>A</sub>-x<sub>B</sub>|, |y<sub>A</sub>-y<sub>B</sub>|, |z<sub>A</sub>-z<sub>B</sub>|)입니다. 이는 세 좌표축 중에서 가장 작은 거리 차이를 선택한다는 의미입니다. 예를…

Process String with Special Operations II

Link: https://leetcode.com/problems/process-string-with-special-operations-ii/ 📖 Interpreting the Problem We’re given a string s composed of lowercase letters and three special characters: *, #, and %. Each character modifies an initially empty string result as we iterate from left to right. After processing the entire string, we’re to return the k-th character of result (0-based). If k is…

Finding the Longest Palindromic Path in a Graph

Link: https://leetcode.com/problems/longest-palindromic-path-in-graph/ 📖 Interpreting the Problem We’re given an undirected graph with n nodes, each labeled with a character. Our goal is to find the maximum possible length of a palindrome that can be formed by visiting a sequence of unique nodes along a valid path. Importantly, we may start at any node and travel…

Coloring a Grid with No Two Adjacent Cells the Same

Link: https://leetcode.com/problems/painting-a-grid-with-three-different-colors/ 📖 Interpreting the Problem Imagine you’re handed an empty grid of size m x n, and you need to fill every single cell using one of three colors: red, green, or blue. However, there’s a twist: no two adjacent cells—either vertically or horizontally—can share the same color. Let’s break it down with a…

All O`one Data Structure

Link: https://leetcode.com/problems/all-oone-data-structure/description/ 📖 Interpreting the Problem Imagine you’re building a dynamic dictionary of strings where each string has an associated counter. Each time you “see” or “use” a string, its counter increases. If a string is no longer needed, its counter decreases. Occasionally, you’d like to ask: “Which string has the highest count right now?”…

Maximum Number of Groups With Increasing Length

📚 Interpreting the Problem Imagine you’re given a list of limits, where each number in the list represents how many times that index can be used in total. You’re tasked with forming groups using numbers from 0 up to n-1, but with two essential conditions: Your goal is to determine the maximum number of such groups that…