MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / CutRodRec

Function CutRodRec

dynamic/rodcutting.go:10–20  ·  view source on GitHub ↗

CutRodRec solve the problem recursively: initial approach

(price []int, length int)

Source from the content-addressed store, hash-verified

8
9// CutRodRec solve the problem recursively: initial approach
10func CutRodRec(price []int, length int) int {
11 if length == 0 {
12 return 0
13 }
14
15 q := -1
16 for i := 1; i <= length; i++ {
17 q = Max(q, price[i]+CutRodRec(price, length-i))
18 }
19 return q
20}
21
22// CutRodDp solve the same problem using dynamic programming
23func CutRodDp(price []int, length int) int {

Callers

nothing calls this directly

Calls 1

MaxFunction · 0.85

Tested by

no test coverage detected