From 27d663a4dfd4fc3ac075a7a3505972251d59f27e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 17 Oct 2022 10:04:44 +0800 Subject: [PATCH] D - How many trees? https://codeforces.com/contest/9/submission/176628922 --- Codeforces/9/D/D.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Codeforces/9/D/D.cpp diff --git a/Codeforces/9/D/D.cpp b/Codeforces/9/D/D.cpp new file mode 100644 index 00000000..609460c0 --- /dev/null +++ b/Codeforces/9/D/D.cpp @@ -0,0 +1,33 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 40; + +int n, h; +long long f[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> h; + + for (int i = 0; i <= n; i++) { + f[0][i] = 1; + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 0; k < i; k++) { + f[i][j] += f[k][j - 1] * f[i - k - 1][j - 1]; + } + } + } + + cout << f[n][n] - f[n][h - 1] << endl; + + return 0; +}