问题描述
样例输入 一个满足题目要求的输入范例。 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(); } } ---来自腾讯云社区的---AI那点小事
微信扫一扫打赏
支付宝扫一扫打赏