问题描述
样例输入 一个满足题目要求的输入范例。 3 10 样例输出 与上面的样例输入对应的输出。 120 数据规模和约定 输入数据中每一个数的范围。 例:结果在int表示时不会溢出。
import java.util.Scanner;
public class Main {
public static int Combination(int n ,int k){
int result;
if ( k == 0 || k == n){
result = 1;
}else{
result = Combination(n-1, k)+Combination(n-1, k-1);
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int k = in.nextInt();
int n = in.nextInt();
System.out.print(Combination(n, k));
in.close();
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有