結果
問題 |
No.1011 Infinite Stairs
|
ユーザー |
|
提出日時 | 2024-10-24 08:05:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,026 bytes |
コンパイル時間 | 919 ms |
コンパイル使用メモリ | 76,904 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-10-24 08:06:02 |
合計ジャッジ時間 | 6,048 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | TLE * 1 -- * 23 |
ソースコード
#include <iostream> #include <map> using namespace std; map<pair<int, int>, 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; }