경쟁 프로그래밍쉬움

로드 절단

'막대 절단' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

price 가격 목록을 취하는 cut_rod(price, n) 함수를 작성하세요. 여기서 price[i]는 길이가 i+1인 막대의 가격이고 전체 길이는 n입니다. 길이가 n인 막대를 자르고 조각을 판매하여 얻을 수 있는 최대 값을 반환합니다.

제약
  • 1 <= n <= 1000
  • len(price) >= n
  • 1 <= price[i] <= 10000

Example 1
Input
cut_rod([1, 5, 8, 9, 10, 17, 17, 20], 8)
Output
22
Explanation

Cut the rod of length 8 into two pieces of length 2 and 6. The total value is 5 + 17 = 22.

Example 2
Input
cut_rod([3, 5, 8, 9, 10, 17, 17, 20], 8)
Output
24
Explanation

Cut the rod of length 8 into eight pieces of length 1. The total value is 8 * 3 = 24.

Need a Hint?
세트나 힙과 같은 동적 프로그래밍 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.