{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "28697aa8d9b94ea4877b314637b97fbe",
  "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": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tvector<vector<int>> combinationSum(vector<int> &candidates, int target)\n\t{\n\t\tvector<vector<int>> res;\n\t\tdfs(candidates, 0, target, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector<int> stack;\n\tvoid dfs(vector<int> &candidates, int start, int target, vector<vector<int>> &res)\n\t{\n\t\tif (target < 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\telse if (target == 0)\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = start; i < candidates.size(); i++)\n\t\t\t{\n\t\t\t\tstack.push_back(candidates[i]);\n\t\t\t\tdfs(candidates, i, target - candidates[i], res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t}\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-58550dadc0174b719c8769c5d87c8814",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600471017"
}