//比如在数组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. 深入分析 Java 中的中文编码问题(转)

    几种常见的编码格式 为什么要编码 不知道大家有没有想过一个问题,那就是为什么要编码?我们能不能不编码?要回答这个问题必须要回到计算机是如何表示我们人类能够理解的符号的,这些符号也就是我们人类使用的语言 ...

  2. Linux查看目录挂载点

    用命令 df 即可 # df /var/lib/ Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 135979984 669 ...

  3. ubuntu 12 64 桌面版Oracle11g 安装

    1.Creating the Oracle Inventory Group sudo groupadd oinstall sudo groupadd dba sudo groupadd oper su ...

  4. js 拼接 三列做为一行

    function Ajax_GetCourseAndResource(data) { $(".ol-course-list").empty(); var html = " ...

  5. poj 3415 Common Substrings(后缀数组+单调栈)

    http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Sub ...

  6. Oracle中的触发器

    创建触发器的语法: Create trigger 触发器的名字 after insert/update/delete/(select是没有触发器的) on 表名字 declare begin dbms ...

  7. 递归解析XML

    package com.app.test; import java.io.InputStream; import java.util.List; import org.dom4j.Attribute; ...

  8. PHP strip_tags() 函数

    定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...

  9. mysql 监控工具monyog使用总结

    1. 下载安装 2. 登录之后,查看 locked queries 2. 慢查询

  10. ANDROID_MARS学习笔记_S02_008_ANIMATION第二种使用方式:xml

    一.简介 二.代码1.res\anim下的xml(1)alpha.xml.xml <?xml version="1.0" encoding="utf-8" ...