結果
問題 |
No.44 DPなすごろく
|
ユーザー |
![]() |
提出日時 | 2018-03-08 08:28:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 745 ms |
コンパイル使用メモリ | 79,568 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-05 07:38:59 |
合計ジャッジ時間 | 1,664 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
// No.44 DPなすごろく // https://yukicoder.me/problems/no/44 // #include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; long long int solve(unsigned int N); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); unsigned int N; cin >> N; long long ans = solve(N); cout << ans << endl; } long long int solve(unsigned int N) { vector<vector<long long>> dp; dp.resize(N+1); for (auto y = 0; y< N+1; ++y) dp[y].resize(N+1); dp[0][0] = 1; for (auto i = 1; i <= N; ++i) { for (auto j = i; j <= N; ++j) { long long t = 0; for (auto k = 1; k <= 2; ++k) { if (j - k < 0) continue; t += dp[i-1][j-k]; } dp[i][j] = t; } } long long total = 0; for (auto i = 0; i <= N; ++i) total += dp[i][N]; return total; }