Advertisement
Guest User

Untitled

a guest
Mar 17th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.StringTokenizer;
  4.  
  5. public class Q {
  6.     FastScanner in;
  7.     PrintWriter out;
  8.  
  9.     public void solve() throws IOException {
  10.         long dp[][] = new long[44][44];
  11.         for (int i = 0; i < 44; i++) {
  12.             dp[i][0] = 1;
  13.             for (int j = 1; j <= i/2; j++) {
  14.                 dp[i][j] += dp[i-1][j];
  15.                 for (int left = 0; left <= i-2; left++) {
  16.                     int right = i-left-2;
  17.                     if (right < 0) continue;
  18.                     for (int left_con = 0; left_con <= (left == 0 ? 0 : j-1); left_con++) {
  19.                         int right_con = j-1-left_con;
  20.                         if (right == 0 && right_con != 0) continue;
  21.                         long m = 1;
  22.                         if (left > 0 || left == 0 && left_con == 0) {
  23.                             m *= dp[left][left_con];
  24.                         }
  25.                         if (right > 0 || right == 0 && right_con == 0) {
  26.                             m *= dp[right][right_con];
  27.                         }
  28.                         dp[i][j] += m;
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.         int n = in.nextInt();
  34.         int k = in.nextInt();
  35.         out.println(dp[n][k]);
  36.     }
  37.  
  38.  
  39.     public void run() {
  40.         try {
  41.             //in = new FastScanner(new File("input.txt"));
  42.             //out = new PrintWriter(new File("output.txt"));
  43.             in = new FastScanner(System.in);
  44.             out = new PrintWriter(System.out);
  45.             //err = new PrintWriter(System.err);
  46.  
  47.             solve();
  48.  
  49.             out.close();
  50.         } catch (IOException e) {
  51.             e.printStackTrace();
  52.         }
  53.     }
  54.  
  55.     class FastScanner {
  56.         BufferedReader br;
  57.         StringTokenizer st;
  58.  
  59.         FastScanner(File f) {
  60.             try {
  61.                 br = new BufferedReader(new FileReader(f));
  62.             } catch (FileNotFoundException e) {
  63.                 e.printStackTrace();
  64.             }
  65.         }
  66.  
  67.         FastScanner(InputStream st) {
  68.             br = new BufferedReader(new InputStreamReader(st));
  69.         }
  70.  
  71.         String next() {
  72.             while (st == null || !st.hasMoreTokens()) {
  73.                 try {
  74.                     st = new StringTokenizer(br.readLine());
  75.                 } catch (IOException e) {
  76.                     e.printStackTrace();
  77.                 }
  78.             }
  79.             return st.nextToken();
  80.         }
  81.  
  82.         int nextInt() {
  83.             return Integer.parseInt(next());
  84.         }
  85.  
  86.         long nextLong() {
  87.             return Long.parseLong(next());
  88.         }
  89.  
  90.         double nextDouble() {
  91.             return Double.parseDouble(next());
  92.         }
  93.  
  94.     }
  95.  
  96.     public static void main(String[] arg) {
  97.         new Q().run();
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement