//比如在数组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. iis7以上版本权限控制

    IIS7.5中(仅win7,win2008 SP2,win2008 R2支持),应用程序池的运行帐号,除了指定为LocalService,LocalSystem,NetWorkService这三种基本 ...

  2. JS的this本质

    1.this究竟为何物? 1.1 全局上下文(Global context ) 在全局运行上下文中(在任何函数体外部),this 指代全局对象window,无论是否在严格模式下. alert(this ...

  3. 组态王6.55WEB全新发布步骤

    转载请... 算了 估计没有人转..自己留着看 目的: 本教程通过组态王6.55实现一个WEB服务器和一个WEB画面的客户端,总共两个工程.服务器工程名为 Server , 客户点为 Client.S ...

  4. custom event in javascript and jquery

    javascript: // add a eventListener document.addEventListener("abc", function(){alert('this ...

  5. cocos2dx伸缩式列表效果

    效果: 代码: ElasticListView.h #pragma once //std #include <string> #include <map> //cocos #i ...

  6. Codeforces Round #328 div2

    Problem_A(592A): 题意: 在一个8*8的棋盘上有黑白两种棋子,'W'代表白色,'B'代表黑色. 玩家A执白子,先走. 白子只能向上走,黑子只能向下走.如果有障碍物则不能走, 比如白色的 ...

  7. 实时动态更新曲线图,x轴时间s随数据的变化而变化

    $(function () {    $(document).ready(function () {        Highcharts.setOptions({            global: ...

  8. How To Call Stored Procedure In Hibernate

    How To Call Stored Procedure In Hibernate In this tutorial, you will learn how to call a store proce ...

  9. opencv 操作本地摄像头实现录像

    直接上代码: // demo1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  10. Html之img标签

    我发现了为什么我不会开发,或者不愿意,我感觉是因为我不会前端,自认为写出来完美的后台显示不好也没人用,为了解决这一问题,笔者新增html栏目,和大家一起交流分享. 一.img必须有src和alt属性 ...