计算公式
Java实现
求C(n,m) //从n个球中取m个的组合种类 public static int C(int n,int m){ if(n==m) return 1; else return JC(n)/(JC(m)*JC(n-m)); } //求阶乘 public static int JC(int num){ if (num==1){ return 1; }else { return JC(num-1)*num; } }
求C(n,1)+C(n,2)+...+C(n,m)
public static int sumOfC(int num){ int sum = 0; if (num == 1){ return 1; }else { for (int i = 1; i <= num; i++) { sum+=C(num,i); } return sum; } }