mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-13 12:20:57 +00:00
feat(go/dp): support dynamic programming (#622)
* feat(go/dp): support climbing stairs * feat(go/dp): support knapsack * feat(go/dp): coin_change & edit_distance
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// File: coin_change_test.go
|
||||
// Created Time: 2023-07-23
|
||||
// Author: Reanon (793584285@qq.com)
|
||||
|
||||
package chapter_dynamic_programming
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCoinChange(t *testing.T) {
|
||||
coins := []int{1, 2, 5}
|
||||
amt := 4
|
||||
|
||||
// 动态规划
|
||||
res := coinChangeDP(coins, amt)
|
||||
fmt.Printf("凑到目标金额所需的最少硬币数量为 %d\n", res)
|
||||
|
||||
// 状态压缩后的动态规划
|
||||
res = coinChangeDPComp(coins, amt)
|
||||
fmt.Printf("凑到目标金额所需的最少硬币数量为 %d\n", res)
|
||||
}
|
||||
Reference in New Issue
Block a user