问一个M简单(可我不会)的问题 10!/4!=10*9*8*7*6*5??????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1000000个组合算法很简单的10的10次方除以10的4次方 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(); }} 是不是ConcurrentHashMap可以替代所有的HashMap Java初学者:eclipse 怎么没有JMF包? 关于抽象类和接口的面试题 SWING的1个小问题! tableViewer无法显示列,求教高手 为什么用IE启动不了applet程序??? 电影管理系统中的问题??急!! 求算法思路 能提供一些讲述用SWING做界面的网站? 关于接口的问题.... 请大侠介绍一本JAVA2D的书 Thinking In Java第二版(中文版本)pdf格式
算法很简单的
10的10次方除以10的4次方
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();
}
}