-
Notifications
You must be signed in to change notification settings - Fork 0
Solve(dp): BOJ 2073 "수도배관공사" 문제 풀이 #12
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||
| import java.io.*; | ||||||||||||||||||||||
| import java.util.*; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class Main { | ||||||||||||||||||||||
| static int D, P; | ||||||||||||||||||||||
| static int[][] pipes; | ||||||||||||||||||||||
| static int[] dp; | ||||||||||||||||||||||
| public static void main(String[] args) throws IOException { | ||||||||||||||||||||||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||||||||||||||||||||||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||||||||||||||||||||||
| D = Integer.parseInt(st.nextToken()); | ||||||||||||||||||||||
| P = Integer.parseInt(st.nextToken()); | ||||||||||||||||||||||
| pipes = new int[P][2]; | ||||||||||||||||||||||
| dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량 | ||||||||||||||||||||||
|
||||||||||||||||||||||
| dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량 | |
| dp = new int[D+1]; // idx 거리까지 도달할 때 가능한 최대 최소 수도관 용량을 저장 |
Copilot
AI
Dec 5, 2025
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.
초기값 100001은 매직 넘버입니다. 의미를 명확히 하기 위해 상수로 선언하는 것이 좋습니다. 예: static final int INF = 100001; 또는 주석으로 "문제의 최대 용량 제약(100000)보다 큰 값"임을 명시해야 합니다.
Copilot
AI
Dec 5, 2025
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.
주석에 띄어쓰기 오류가 있습니다: "더해서 i가 될때" → "더해서 i가 될 때"
| for(int i = D;i>= d;i--){ // 더해서 i가 될때 | |
| for(int i = D;i>= d;i--){ // 더해서 i가 될 때 |
Copilot
AI
Dec 5, 2025
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.
[nitpick] 띄어쓰기가 누락되었습니다: i>= → i >=
| for(int i = D;i>= d;i--){ // 더해서 i가 될때 | |
| for(int i = D; i >= d; i--){ // 더해서 i가 될때 |
Copilot
AI
Dec 5, 2025
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.
변수명 d와 p가 너무 짧고 모호합니다. length와 capacity 또는 pipeLength와 pipeCapacity로 변경하면 가독성이 향상됩니다.
| int d = pipe[0]; | |
| int p = pipe[1]; | |
| for(int i = D;i>= d;i--){ // 더해서 i가 될때 | |
| dp[i] = Math.max(dp[i], Math.min(p, dp[i-d])); | |
| int length = pipe[0]; | |
| int capacity = pipe[1]; | |
| for(int i = D; i >= length; i--){ // 더해서 i가 될때 | |
| dp[i] = Math.max(dp[i], Math.min(capacity, dp[i-length])); |
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.
주석에 오타가 있습니다: "거리르" → "거리를"