学到新知识:求排列组合
2018-03-20 17:18
197 查看
给你整数n和,让你求组合数c(n,k)。
#include <cstdio>
#include <cstring>
#include <math.h>
typedef long long LL;
LL ans,n,k;
int main()
{
while(scanf("%lld%lld",&n,&k),n)
{
ans=1;
if(k == 0)
{
printf("1\n");
continue;
}
k=n-k>k?k:n-k;
//if(k>n-k)k=n-k;
for(int i=1; i<=k; i++)
{
ans=ans*(n-i+1)/i;
}
printf("%lld\n",ans);
}
return 0;
}相关题目:https://community.topcoder.com/stat?c=problem_statement&pm=14857
#include <cstdio>
#include <cstring>
#include <math.h>
typedef long long LL;
LL ans,n,k;
int main()
{
while(scanf("%lld%lld",&n,&k),n)
{
ans=1;
if(k == 0)
{
printf("1\n");
continue;
}
k=n-k>k?k:n-k;
//if(k>n-k)k=n-k;
for(int i=1; i<=k; i++)
{
ans=ans*(n-i+1)/i;
}
printf("%lld\n",ans);
}
return 0;
}相关题目:https://community.topcoder.com/stat?c=problem_statement&pm=14857
相关文章推荐
- 机器学习(2.3)数据知识积累——排列组合
- 8_14 日学到的新知识(简单的工厂模式的实现, MVC 模式的基本概念,软件工程中的四种开发模型, 以及软件工程中的一些小知识点)
- 牛客网做题学到的知识(五)
- 2016-11-24关于jquery ajax 和spring拦截器学到的新知识
- 看了老大的博客。总结一下学到的知识
- 贪吃蛇学到的知识
- 自己瞎打误撞学到的知识
- 教你快速学习SEO知识,ppjms在实践中掌握学到的知识
- cocos2d-x 2.x 转 3.x 学到的知识(其他 部分)
- 看mysql手册中模式(SQL_MODE)学到的知识
- 从网上学到的一个消息相关知识
- 今天第一次在杭电做题,虽然做的题比较简单,出错也依旧多,花费了很长时间,不过很开心,还学到一些知识,继续努力
- 原子操作的一段代码学到的知识
- 怎样判断自己掌握了学到的新知识
- 05-最近学到的一些知识的总结
- 看了PullToZoomListView学到的知识
- 今天学到的新知识
- 希望能够学到更多的知识
- 三个你在书中无法学到的数据分析知识