10!/4!=10*9*8*7*6*5
???????????

解决方案 »

  1.   

    1000000个组合
    算法很简单的
    10的10次方除以10的4次方
      

  2.   

    welcome to 
    http://www.chinaunix.net/forum/viewforum.php?f=26try this:/*NumberTestcombin.java
    *code by Serol Luo, [email protected]
    */
    import java.util.*;public class NumberTestCombine{public static void main(String arg[]){
    int m=0;
    int n=0;
    if (arg.length != 2){
    usage();
    System.exit(1);

    try{
    m=Integer.parseInt(arg[0]);
    n=Integer.parseInt(arg[1]);
    }
    catch(NumberFormatException e){
    System.out.println(e);
    usage();
    System.exit(1);
    }
    Integer[] o=new Integer[m];
    for (int i=0;i<m ;i++ )
    o[i]=new Integer(i+1);
    Combine c=new Combine(o,n);
    System.out.println("从1到"+m+"中抽出"+n+"个数,共有"+c.getsize()+"种方式");
    try{
    while(true){
    System.out.println(c.next());
    }
    }
    catch(Exception e){}}private static void usage(){
    System.out.println("Usage:java NumberTestcombin number1 number 2");
    }}class Combine
    {
    private HashSet combineList;
    private Iterator c;
    public Combine(Object object[],int select){
            combineList=makeList(object,select);
    c=combineList.iterator();
    }  //利用递归调用创造一个object[] -- n的全组合
      private static final HashSet makeList(Object o[],int n){
        HashSet list=new HashSet();
    int m=o.length;
        if (n == 0) {
    HashSet v=new HashSet();
    v.add(new HashSet());
    return v;
        }
        else {
         HashSet list2 = makeList(o,n - 1);
      for(Iterator i=list2.iterator();i.hasNext();){
      HashSet h=(HashSet)i.next();
              HashSet h2=(HashSet)(h.clone());
      for(int k=0;k<m;k++){
    if(h2.add(o[k])){
    list.add(h2);
    h2=(HashSet)(h.clone());
      }
      }
      }
    }
       System.out.println(list.size()+" "+n);
        return list;
       }
    public HashSet next(){
    return (HashSet)(c.next());
    }
    public boolean hasNext(){
    return c.hasNext();
    }  public int getsize(){
        return combineList.size();
      }
    }