結果

問題 No.44 DPなすごろく
ユーザー kichirb3kichirb3
提出日時 2018-03-08 08:28:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 958 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 79,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 12:01:39
合計ジャッジ時間 1,626 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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;
}
0