美文网首页
java学习

java学习

作者: iOSjiang | 来源:发表于2016-05-19 23:05 被阅读20次

从N个数字中取出K个数字共有多少种取法Cn

n*(n-1)*(n-2)*(n-3)....(n-k+1)/1*2*3*...*k

用java代码:

public static int getCount(int n,int k)

{

int count = 1;

for(int i = 1;i<=k;i++)

{

count = count * (n-i+1)/i;

}

return count;

}

相关文章

网友评论

      本文标题:java学习

      本文链接:https://www.haomeiwen.com/subject/vapjrttx.html