Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- public class Q {
- FastScanner in;
- PrintWriter out;
- public void solve() throws IOException {
- long dp[][] = new long[44][44];
- for (int i = 0; i < 44; i++) {
- dp[i][0] = 1;
- for (int j = 1; j <= i/2; j++) {
- dp[i][j] += dp[i-1][j];
- for (int left = 0; left <= i-2; left++) {
- int right = i-left-2;
- if (right < 0) continue;
- for (int left_con = 0; left_con <= (left == 0 ? 0 : j-1); left_con++) {
- int right_con = j-1-left_con;
- if (right == 0 && right_con != 0) continue;
- long m = 1;
- if (left > 0 || left == 0 && left_con == 0) {
- m *= dp[left][left_con];
- }
- if (right > 0 || right == 0 && right_con == 0) {
- m *= dp[right][right_con];
- }
- dp[i][j] += m;
- }
- }
- }
- }
- int n = in.nextInt();
- int k = in.nextInt();
- out.println(dp[n][k]);
- }
- public void run() {
- try {
- //in = new FastScanner(new File("input.txt"));
- //out = new PrintWriter(new File("output.txt"));
- in = new FastScanner(System.in);
- out = new PrintWriter(System.out);
- //err = new PrintWriter(System.err);
- solve();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- class FastScanner {
- BufferedReader br;
- StringTokenizer st;
- FastScanner(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- FastScanner(InputStream st) {
- br = new BufferedReader(new InputStreamReader(st));
- }
- String next() {
- while (st == null || !st.hasMoreTokens()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- long nextLong() {
- return Long.parseLong(next());
- }
- double nextDouble() {
- return Double.parseDouble(next());
- }
- }
- public static void main(String[] arg) {
- new Q().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement