Created
December 24, 2020 15:43
-
-
Save zzuummaa/43c9d7227675007c3fb8ef237787ad8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://codeforces.com/contest/9/problem/D | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
const int MAX_N = 35; | |
void assign_sum(std::vector<uint64_t>& a, const std::vector<uint64_t>& b) { | |
for (int i = 0; i < std::min(a.size(), b.size()); i++) { | |
a[i] += b[i]; | |
} | |
} | |
int main() { | |
int n, h; | |
std::cin >> n >> h; | |
std::vector<std::vector<uint64_t>> count_by_n_h(MAX_N + 1); | |
count_by_n_h[0].push_back(1); | |
count_by_n_h[1].push_back(0); | |
count_by_n_h[1].push_back(1); | |
count_by_n_h[2].push_back(0); | |
count_by_n_h[2].push_back(0); | |
count_by_n_h[2].push_back(2); | |
count_by_n_h[3].push_back(0); | |
count_by_n_h[3].push_back(0); | |
count_by_n_h[3].push_back(1); | |
count_by_n_h[3].push_back(4); | |
std::vector<uint64_t> count_by_h; | |
for (int i = 4; i <= n; ++i) { | |
count_by_h.resize(i, 0); | |
for (int j = 0; j < i; j++) { | |
assign_sum(count_by_h, count_by_n_h[j]); | |
assign_sum(count_by_h, count_by_n_h[i - (j + 1)]); | |
} | |
std::rotate(count_by_h.rbegin(), count_by_h.rbegin() + 1, count_by_h.rend()); | |
count_by_n_h[i] = count_by_h; | |
} | |
const auto& vec = count_by_n_h[n]; | |
std::cout << std::accumulate(vec.begin() + h, vec.end(), 0ull); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment