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 {
private:
vector<vector<int>> res;
int myn;
int num;
public:
void tra(int loc,int start,vector<int> temp){
if(loc==num+)
{
res.push_back(temp);
return;
}
for (int i=start;i<=myn;++i)
{
temp.push_back(i);
tra(loc+,i+,temp);//不是start+1,而是i+1
temp.erase(temp.end()-);
}
}
vector<vector<int>> combine(int n, int k) {
myn=n;
num=k;
vector<int> temp;
tra(,,temp);
return res;
}
};

  注释处是i+1,原因在于

												

Combinations(带for循环的DFS)的更多相关文章

  1. Letter Combinations of a Phone Number(带for循环的DFS,组合问题,递归总结)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  2. 【转】Android开发实践:自定义带消息循环(Looper)的工作线程

    http://ticktick.blog.51cto.com/823160/1565272 上一篇文章提到了Android系统的UI线程是一种带消息循环(Looper)机制的线程,同时Android也 ...

  3. LeetCode Letter Combinations of a Phone Number (DFS)

    题意 Given a digit string, return all possible letter combinations that the number could represent. A ...

  4. 在不开启事件循环的线程中使用QTimer(QThread::run函数自带事件循环,在构造函数里创建线程,是一种很有意思的线程用法) good

    引入 QTimer是Qt自带的定时器类,QTimer运行时是依赖于事件循环的,简单来说,在一个不开启事件循环(未调用exec() )的线程中,QTimer是无法使用的.通过分析Qt源码可发现,调用QT ...

  5. ping IP 带时间戳循环显示并写入日志(windos版+linux版)

    在工作中,判断网络是否通畅,首选命令就是ping,但有时候我们需要持续ping一个或多个地址时,需要加 -t 即可,但有时候需要在ping的时候加入时间戳并把ping记录写入到日志里面,方法如下: w ...

  6. Word Search(深度搜索DFS,参考)

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  7. angular.foreach 循环方法使用指南

    angular有自己的生命周期.循环给一个 angular监听的变量复值时.最好还是用angular自带的循环方法.“angular.foreach” },{a:}]; angular.forEach ...

  8. [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  9. bzoj 1574: [Usaco2009 Jan]地震损坏Damage【dfs】

    和March的那道不一样,只是非常单纯的带着贪心的dfs 首先一个点被隔断,与它相邻的所有点也会被隔断,打上删除标记,从1dfs即可 #include<iostream> #include ...

随机推荐

  1. swiper4实现的拥有header和footer的全屏滚动demo/swiper fullpage footer

    用swiper4实现的拥有header和footer的全屏滚动demo, <!DOCTYPE html> <html lang="en"> <head ...

  2. Android 实现对多个EditText的监听

    create_account=(EditText)findViewById(R.id.create_account); create_password=(EditText)findViewById(R ...

  3. 掌握Spark机器学习库-06-基础统计部分

    说明 本章主要讲解基础统计部分,包括基本统计.假设检验.相关系数等 数据集 数据集有两个文件,分别是: beijing.txt 北京历年降水量,不带年份 beijing2.txt 北京历年降水量,带年 ...

  4. 关于TREEVIEW的ONSELECTEDNODECHANGED事件

    MSDN:http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.treeview.selectednodechanged( ...

  5. VS2015 update3 安装 asp.net core 失败

    CMD 命令下执行: C:\DotNetCore\DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1

  6. IMX6核心板系列解决方案-工业级|商业级|四核|双核|Plus核心板

    i.MX 6Quad四核商业级和工业级系列的应用处理器将可扩展平台与广泛的集成和高能效处理功能相结合,尤其适合多媒体应用.i.MX6 Quad处理器的特性包括: 满足操作系统和游戏的MIPS需求,增强 ...

  7. codeforces_B. Forgery

    http://codeforces.com/contest/1059/problem/B 题意: For simplicity, the signature is represented as an  ...

  8. MySQL性能优化之max_connections配置

    MySQL的最大连接数,增加该值增加mysqld 要求的文件描述符的数量.如果服务器的并发连接请求量比较大,建议调高此值,以增加并行连接数量,当然这建立在机器能支撑的情况下,因为如果连接数越多,介于M ...

  9. laravel UserRequest $request error

    laravel UserRequest $request error Ask Question   0   laravel5.2,I create a UserRequest.php under Re ...

  10. bash - GNU Bourne-Again SHell

    概述(SYNOPSIS) bash [options] [file] 版权所有(COPYRIGHT) Bash is Copyright (C) 1989-2002 by the Free Softw ...