算法训练 6-1 递归求二项式系数值
生活随笔
收集整理的這篇文章主要介紹了
算法训练 6-1 递归求二项式系数值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
算法訓練 6-1 遞歸求二項式系數值 ? 問題描述 樣例輸入 一個滿足題目要求的輸入范例。
3 10 樣例輸出 與上面的樣例輸入對應的輸出。
數據規模和約定 輸入數據中每一個數的范圍。
例:結果在int表示時不會溢出。 import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int k = sc.nextInt();int n = sc.nextInt();sc.close();System.out.println(C(k, n));}static int C(int k, int n) {if (k == 0 || k == n) {return 1;} elsereturn C(k, n - 1) + C(k - 1, n - 1);} }
3 10 樣例輸出 與上面的樣例輸入對應的輸出。
數據規模和約定 輸入數據中每一個數的范圍。
例:結果在int表示時不會溢出。 import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int k = sc.nextInt();int n = sc.nextInt();sc.close();System.out.println(C(k, n));}static int C(int k, int n) {if (k == 0 || k == n) {return 1;} elsereturn C(k, n - 1) + C(k - 1, n - 1);} }
?
轉載于:https://www.cnblogs.com/Alpharun/p/8623071.html
總結
以上是生活随笔為你收集整理的算法训练 6-1 递归求二项式系数值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ROS与navigation教程——概述
- 下一篇: ROS multi-master——mu