Advertisement
chenyunchen

Algorithm - hw#1

Mar 28th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Main {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int num = scanner.nextInt();
  6.         System.out.println(f(num));
  7.     }
  8.     public static int f(int n) {
  9.         if (n == 1)
  10.             return 1;
  11.         else {
  12.             int sum = 0;
  13.             for(int k = 1;k < n;k++)
  14.               sum = sum + f(k) * f(n - k);
  15.             return sum;
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement