// UVa 10157 - Expressions
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static int MX = 151;
static BigInteger[][] a = new BigInteger[MX][MX];
static void dp() {
for (int t = 0; t < MX; t++) {
a[0][t] = BigInteger.ONE;
}
for (int i = 1; i < MX; i++) {
a[i][0] = BigInteger.ZERO;
for (int t = 1; t <= i; t++) {
a[i][t] = BigInteger.ZERO;
for (int j = 1; j <= i; j++)
a[i][t] = a[i][t]
.add(a[j - 1][t - 1].multiply(a[i - j][t]));
}
for (int t = i + 1; t < MX; t++)
a[i][t] = a[i][t - 1];
}
}
public static void main(String[] args) {
dp();
try (Scanner scan = new Scanner(System.in)) {
while (scan.hasNextInt()) {
int x = scan.nextInt();
int y = scan.nextInt();
if (x % 2 == 1) {
System.out.println(0);
continue;
}
x /= 2;
System.out.println(a[x][y].subtract(a[x][y - 1]));
}
}
}
}
Monday, May 4, 2015
UVa 10157 - Expressions
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment