/*
ID: BryatnMark
LANG: JAVA
TASK: AC
*/
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.main(in, out);
out.close();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
String next() {
if (!hasNext())
throw new RuntimeException();
return tokenizer.nextToken();
}
boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
return false;
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
class Task {
BigInteger[] fact = new BigInteger[102];
BigInteger[][] f = new BigInteger[102][102];
BigInteger[][] c = new BigInteger[102][102];
BigInteger one = BigInteger.ONE;
BigInteger zero = BigInteger.ZERO, two = BigInteger.valueOf(2);
void main(InputReader in, PrintWriter out) throws Exception {
int i, j, k, t;
int n = in.nextInt();
for (i = 0; i <= n; ++i)
c[i][0] = c[i][i] = one;
for (i = 1; i <= n; ++i)
for (j = 1; j < i; ++j)
c[i][j] = c[i - 1][j - 1].add(c[i - 1][j]);
for (i = 0; i <= n; ++i)
for (j = 0; j * 3 <= n; ++j)
f[i][j] = zero;
f[3][1] = one;
fact[0] = fact[1] = fact[2] = one;
for (i = 3; i <= n; ++i)
fact[i] = fact[i - 1].multiply(BigInteger.valueOf(i));
for (i = 4; i <= n; ++i) {
f[i][1] = fact[i - 1];
for (j = 3; j <= i - 3; ++j) {
t = (i - j) / 3;
for (k = 1; k <= t; ++k) {
f[i][k + 1] = f[i][k + 1].add(c[i][j].multiply(f[i - j][k]
.multiply(f[j][1])));
}
}
t = i / 3;
for (k = 2; k <= t; ++k)
f[i][k] = f[i][k].divide(BigInteger.valueOf(k));
}
BigInteger ans = zero;
for (i = 1; i * 3 <= n; ++i)
ans = ans.add(f[n][i]);
out.println(ans);
}
}
POJ System
最新推荐文章于 2018-04-11 22:30:24 发布