{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "73cb72426b5641b3b80c60652041a104",
  "keywords": "数组,回溯",
  "title": "组合总和",
  "desc": [
    {
      "content": "\n<p>给定一个<strong>无重复元素</strong>的数组&nbsp;<code>candidates</code>&nbsp;和一个目标数&nbsp;<code>target</code>&nbsp;，找出&nbsp;<code>candidates</code>&nbsp;中所有可以使数字和为&nbsp;<code>target</code>&nbsp;的组合。\n</p>\n<p><code>candidates</code>&nbsp;中的数字可以无限制重复被选取。</p>\n<p><strong>说明：</strong></p>\n<ul>\n<li>所有数字（包括&nbsp;<code>target</code>）都是正整数。</li>\n<li>解集不能包含重复的组合。&nbsp;</li>\n</ul>\n<p><strong>示例&nbsp;1：</strong></p>\n<pre><strong>输入：</strong>candidates = [2,3,6,7], target = 7,<strong><br />输出：</strong>[[7],[2,2,3]]</pre>\n<p><strong>示例&nbsp;2：</strong></p>\n<pre><strong>输入：</strong>candidates = [2,3,5], target = 8,<strong><br />输出：</strong>[[2,2,2,2],[2,3,3],[3,5]]</pre>\n<p>&nbsp;</p>\n<p><strong>提示：</strong></p>\n<ul>\n<li><code>1 &lt;= candidates.length &lt;= 30</code></li>\n<li><code>1 &lt;= candidates[i] &lt;= 200</code></li>\n<li><code>candidate</code> 中的每个元素都是独一无二的。</li>\n<li><code>1 &lt;= target &lt;= 500</code></li>\n</ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef combinationSum(self, candidates, target):\n\t\tcandidates.sort()\n\t\tdp = [[] for _ in range(target + 1)]\n\t\tdp[0].append([])\n\t\tfor i in range(1, target + 1):\n\t\t\tfor j in range(len(candidates)):\n\t\t\t\tif candidates[j] > i:\n\t\t\t\t\tbreak\n\t\t\t\tfor k in range(len(dp[i - candidates[j]])):\n\t\t\t\t\ttemp = dp[i - candidates[j]][k][:]\n\t\t\t\t\tif len(temp) > 0 and temp[-1] > candidates[j]:\n\t\t\t\t\t\tcontinue\n\t\t\t\t\ttemp.append(candidates[j])\n\t\t\t\t\tdp[i].append(temp)\n\t\treturn dp[target]\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.combinationSum([8,7,4,3], 11))",
    "language": "python"
  },
  "node_id": "dailycode-55947e6bb1d6408ca60413a7d03f7e38",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600471017"
}