From 5243b5eac0ca69b59d6dac1a5e8dd50bd7a94fd9 Mon Sep 17 00:00:00 2001 From: zhangzw Date: Tue, 8 Jun 2021 15:24:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00377.=E7=BB=84=E5=90=88?= =?UTF-8?q?=E6=80=BB=E5=92=8C=E2=85=A3=20Go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0377.组合总和Ⅳ.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index c6dc3d42..d0394706 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -183,7 +183,23 @@ class Solution: Go: - +```go +func combinationSum4(nums []int, target int) int { + //定义dp数组 + dp := make([]int, target+1) + // 初始化 + dp[0] = 1 + // 遍历顺序, 先遍历背包,再循环遍历物品 + for j:=0;j<=target;j++ { + for i:=0 ;i < len(nums);i++ { + if j >= nums[i] { + dp[j] += dp[j-nums[i]] + } + } + } + return dp[target] +} +```