{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "ee4e57be8bf44e5aa1032d69b3fe55b2",
  "keywords": "数组,回溯",
  "title": "组合",
  "desc": [
    {
      "content": "\n<p>给定两个整数 <em>n</em> 和 <em>k</em>，返回 1 ... <em>n </em>中所有可能的 <em>k</em> 个数的组合。</p>\n<p><strong>示例:</strong></p>\n<pre><strong>输入:</strong>&nbsp;n = 4, k = 2<strong><br />输出:</strong>[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]</pre>",
      "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>> combine(int n, int k)\n\t{\n\t\tvector<vector<int>> res;\n\t\tdfs(n, k, 1, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector<int> stack;\n\tvoid dfs(int n, int k, int start, vector<vector<int>> &res)\n\t{\n\t\tif (stack.size() == k)\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 <= n; i++)\n\t\t\t{\n\t\t\t\tstack.push_back(i);\n\t\t\t\tdfs(n, k, i + 1, res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t}\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-66904ffb7b03468eaac045c49a84d854",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600470921"
}