//比如在数组a[]={1,7,89,87} 中k=2的时候 组合为 C(4,2)=6 

package 再次开始;

import java.util.ArrayList;

//本次实现的是在n个不重复树中提取k个;输出各种组合
//在 1 2 3 7 8 public class 组合问题 {
public static void main(String args[])
{ int arr[]=new int[]{1,3,4,6,9};//
ArrayList<Integer> arry=new ArrayList<Integer>();//用于保存当前的求得的序列 dfs(arr,arry, 3, 0); }
// arry 原始排序数组, k表示取多少个,start表示当前可以选取的下标
private static void dfs(int[] arr,ArrayList<Integer> arry, int k, int start) {
// TODO Auto-generated method stub if(arry.size()==k)
{
System.out.println(arry);
return; }
else
{
for(int i=start;i<arr.length;i++)
{
arry.add(arr[i]);
dfs(arr,arry,k,i+1);
arry.remove(arry.size()-1); } } } }

ref:http://blog.csdn.net/u010500263/article/details/18435495

int arr[]=new int[]{1,3,4,6,9};取得3个

[1, 3, 4]
[1, 3, 6]
[1, 3, 9]
[1, 4, 6]
[1, 4, 9]
[1, 6, 9]
[3, 4, 6]
[3, 4, 9]
[3, 6, 9]
[4, 6, 9]

C(n,k)在n个不重复数中获得k个数的更多相关文章

  1. [Swift]LeetCode668. 乘法表中第k小的数 | Kth Smallest Number in Multiplication Table

    Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...

  2. Leetcode 668.乘法表中第k小的数

    乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 1: 输入 ...

  3. LeetCode 378. 有序矩阵中第K小的元素(Kth Smallest Element in a Sorted Matrix) 13

    378. 有序矩阵中第K小的元素 378. Kth Smallest Element in a Sorted Matrix 题目描述 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩 ...

  4. Java实现 LeetCode 668 乘法表中第k小的数(二分)

    668. 乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 ...

  5. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  6. [LeetCode] Kth Largest Element in an Array 数组中第k大的数字

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  7. 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。

    题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除. 输入: 两个整数n(2<=n<=1000),a(2<=a<=1000) 输出: 一个整数. ...

  8. 线性时间O(n)内求数组中第k大小的数

    --本文为博主原创,转载请注明出处 因为最近做的WSN(wireless sensor network)实验要求用3个传感器节点接受2000个包的数据并算出一些统计量,其中就有算出中位数这么一个要求, ...

  9. 数组中第K小的数字(Google面试题)

    http://ac.jobdu.com/problem.php?pid=1534 题目1534:数组中第K小的数字 时间限制:2 秒 内存限制:128 兆 特殊判题:否 提交:1120 解决:208 ...

随机推荐

  1. 关于Angular.js Routing 的学习笔记(实现单页应用)

    最近开始学习angular.js,发现angular.js确实很方便,也很强大.在看到 AngularJS Routing and Multiple Views 这一部分的时候,有点乱.现在通过记录一 ...

  2. python27读书笔记0.3

    #-*- coding:utf-8 -*- ##D.has_key(k): A predicate that returns True if D has a key k.##D.items(): Re ...

  3. 调试NodeJS应用

    OS:Windows 1.下载安装NodeJS 点击http://nodejs.org/界面上“Install”,下载后运行安装,默认安装到到C:\Program Files\nodejs.安装后确认 ...

  4. ServiceController组件控制计算机服务

    private void Form1_Load(object sender, EventArgs e) { //下面的示例使用 ServiceController 类检查IIS服务是否已停止.如果该服 ...

  5. windows store app Lifecycle

    1.Activated 2.Suspended 3.Resumed 4.Terminated 对应的 js代码: (function () { "use strict"; WinJ ...

  6. Mongodb FAQ fundamentals(基础篇)

    Mongodb FAQ(基础篇),是官方文档的翻译.如有翻译不到之处,还请谅解. 1.Mongdb是什么数据库? mongodb是一个面向文档(document)的数据库,既不支持表连接,也不支持事务 ...

  7. 今日网站突然报错,mysql的故障

    Access denied for user 'root'@'localhost' (using password: YES) 错误位置 FILE: /var/www/html/ThinkPHP/Li ...

  8. C#读取Excel五种方式的体会

    原地址: http://blog.csdn.net/dapengbusi/article/details/38117817 http://blog.csdn.net/dapengbusi/articl ...

  9. 数据库备份,远程执行SHELL脚本

    小小的东东,用于数据库的备份. 留存. #!/bin/sh keepDays= currentTime=`date "+%Y-%m-%d-%H-%M"` backPath=&quo ...

  10. [Gauss]POJ2065 SETI

    题意: *代表0,a-z代表1-26 题目第三行给了一个公式 f (k) = $\sum\limits_{i=0}^{n-1} a_i k^i \pmod{P}$  {f(i)是输入的一串字符串中第i ...