Combinations
来源:互联网 发布:中日关系走向 知乎 编辑:程序博客网 时间:2024/06/13 07:13
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
class Solution {public: vector<vector<int> > res; void execute(int& n,int cur, int count, vector<int>& pre) { if (count-- == 0) { res.push_back(pre); return; } for (int i = cur; i + count <= n; i++) { pre.push_back(i); execute(n, i + 1, count, pre); pre.pop_back(); } } vector<vector<int> > combine(int n, int k) { res.clear(); vector<int> pre; execute(n, 1, k, pre); return res; }};
0 0
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- combinations
- Combinations
- Combinations
- Combinations
- Combinations
- 软件项目管理流程总结
- iOS 使用ASIHTTPRequest实现图片下载,断点续传,cell自定义
- 非交互分割的背景去除
- 远程访问MySQL
- jsp页面上传图片之后页面,当前页面的显示上传的图片可以自行更新
- Combinations
- OpenMp 个人笔记(一)
- javascritp知识点
- HDU 1213 How Many Tables
- 人生
- Android开发之获取联系人信息
- 佛,我心中的一朵莲花
- 哈希(hdu 1280 && 1425 && 1264 && 1496 && 2522 && 2600)
- 管理上的心得分享(一)