#include #include using namespace std; map, long long> memo; // Memoization map // Memoized function with proper cut-off for invalid paths long long get(int id, int n, int d, int k) { // If the state has been computed, return the result if (memo.count({id, n})) return memo[{id, n}]; // Base case: when no steps are left if (n == 0) { // We can only return 1 if we have exactly reached k return (id == k) ? 1 : 0; } // Prune the invalid path: if id exceeds k, it's impossible to reach k now if (id > k) return 0; long long result = 0; // Try all possible next steps (from 1 to d) for (int i = 1; i <= d; i++) { result += get(id + i, n - 1, d, k); } // Store result in the memoization map return memo[{id, n}] = result; } void solve() { int n, d, k; cin >> n >> d >> k; long long ans = get(0, n, d, k); cout << ans << '\n'; } int main() { solve(); return 0; }