Skip to content

Solve(dp): BOJ 2073 "수도배관공사" 문제 풀이#12

Merged
longrunpc merged 1 commit into
solvedfrom
boj/2073
Dec 8, 2025
Merged

Solve(dp): BOJ 2073 "수도배관공사" 문제 풀이#12
longrunpc merged 1 commit into
solvedfrom
boj/2073

Conversation

@longrunpc

Copy link
Copy Markdown
Contributor

📘 문제 정보


✅ 정답(PR)인 경우 작성

1) 최종 풀이 요약

  • 해결 방법 핵심: 배낭문제와 유사한 dp
  • 사용한 알고리즘/자료구조: dp

2) 시간/공간 복잡도

  • 시간 복잡도: O(D*P)
  • 공간 복잡도: O(D)

🎯 리뷰 요청 포인트

  • 검토받고 싶은 부분:
  • 더 효율적인 풀이 가능 여부:
  • 코드 스타일 / 구조 개선 의견 요청:

📝 기타

  • 초반에 해결 알고리즘으로의 접근은 쉬웠지만, 점화식을 세울때의 실수와 같은 길이의 배관을 따로 해결하려고 생각하여 시간이 오래걸렸다.
  • dp문제의 숙련도를 더욱 향상 시킬 필요를 느낌.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

이 PR은 BOJ 2073번 "수도배관공사" 문제를 동적 프로그래밍으로 해결한 풀이입니다. 배낭 문제(knapsack problem)와 유사한 접근법을 사용하여, 주어진 거리 D를 채우면서 최소 용량(병목)을 최대화하는 문제를 해결합니다.

  • 0-1 배낭 문제 방식의 DP를 사용하여 각 거리에서 달성 가능한 최대 최소 용량을 계산
  • 역순 순회를 통해 각 배관을 한 번만 사용하도록 보장
  • 배관을 길이 순으로 정렬하여 효율적인 처리

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

D = Integer.parseInt(st.nextToken());
P = Integer.parseInt(st.nextToken());
pipes = new int[P][2];
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 오타가 있습니다: "거리르" → "거리를"

Suggested change
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량
dp = new int[D+1]; // idx 거리를 구하는 최대 수도관 용량

Copilot uses AI. Check for mistakes.
D = Integer.parseInt(st.nextToken());
P = Integer.parseInt(st.nextToken());
pipes = new int[P][2];
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 오타가 있습니다: "idx 거리를 구하는" → "idx 거리까지 도달할 때"가 더 명확합니다. 현재 주석은 의미가 불명확합니다. DP 배열이 "특정 거리까지 도달할 때 가능한 최대 최소 용량"을 저장한다는 것을 명확히 표현해야 합니다.

Suggested change
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량
dp = new int[D+1]; // idx 거리까지 도달할 때 가능한 최대 최소 수도관 용량을 저장

Copilot uses AI. Check for mistakes.
}

Arrays.sort(pipes, Comparator.comparing(a -> a[0]));
dp[0] = 100001;

Copilot AI Dec 5, 2025

Copy link

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 uses AI. Check for mistakes.
Comment on lines +25 to +29
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]));

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 dp가 너무 짧고 모호합니다. lengthcapacity 또는 pipeLengthpipeCapacity로 변경하면 가독성이 향상됩니다.

Suggested change
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]));

Copilot uses AI. Check for mistakes.
int d = pipe[0];
int p = pipe[1];

for(int i = D;i>= d;i--){ // 더해서 i가 될때

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 띄어쓰기 오류가 있습니다: "더해서 i가 될때" → "더해서 i가 될 때"

Suggested change
for(int i = D;i>= d;i--){ // 더해서 i가 될때
for(int i = D;i>= d;i--){ // 더해서 i가 될 때

Copilot uses AI. Check for mistakes.
int d = pipe[0];
int p = pipe[1];

for(int i = D;i>= d;i--){ // 더해서 i가 될때

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] 띄어쓰기가 누락되었습니다: i>=i >=

Suggested change
for(int i = D;i>= d;i--){ // 더해서 i가 될때
for(int i = D; i >= d; i--){ // 더해서 i가 될때

Copilot uses AI. Check for mistakes.
@longrunpc

Copy link
Copy Markdown
Contributor Author

@copilot
다른 풀이가 있는지 알려주고 다른 풀이도 추천해줘

Copilot AI commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

@longrunpc I've opened a new pull request, #13, to work on those changes. Once the pull request is ready, I'll request review from you.

@longrunpc
longrunpc merged commit a13f9e6 into solved Dec 8, 2025
6 checks passed
@longrunpc
longrunpc deleted the boj/2073 branch December 8, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants