蓝桥杯 算法训练 6-1 递归求二项式系数值

版权声明:对您有帮助的话,求您免费的关注和点赞 https://blog.csdn.net/weixin_42069140/article/details/89716966

问题描述

        

样例输入

        一个满足题目要求的输入范例。
        3 10

样例输出

        与上面的样例输入对应的输出。

        

数据规模和约定

  输入数据中每一个数的范围。
  例:结果在int表示时不会溢出。

时间限制:10.0s  

内存限制:256.0MB

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		System.out.println(fun(a, b));
		s.close();
	}

	public static int fun(int a, int b) {
		if (a == 0 || a == b) {
			return 1;
		} else {
			return fun(a, b - 1) + fun(a - 1, b - 1);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42069140/article/details/89716966