結果

問題 No.1111 コード進行
ユーザー merom686
提出日時 2020-07-10 22:19:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 90,800 KB
最終ジャッジ日時 2025-01-11 18:41:30
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

struct X {
    int p, q, c;
};

ll dp[300][300][301];//i番目まで見てlで終わって複雑さがc
X x[300];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    n--;

    for (int j = 0; j < m; j++) {
        int p, q, c;
        cin >> p >> q >> c;
        p--; q--;
        x[j] = { p, q, c };
    }

    for (int l = 0; l < 300; l++) {
        dp[0][l][0] = 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            auto [p, q, c] = x[j];
            for (int h = c; h <= k; h++) {
                dp[i + 1][q][h] += dp[i][p][h - c];
            }
        }
        for (int l = 0; l < 300; l++) {
            for (int h = 0; h <= k; h++) {
                dp[i + 1][l][h] %= P;
            }
        }
    }

    ll r = 0;
    for (int l = 0; l < 300; l++) {
        r += dp[n][l][k];
    }
    cout << r % P << endl;

    return 0;
}
0