結果

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

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
const ll MOD = 1e9+7;
int main() {
    ll n,m,k;
    std::cin >> n>>m>>k;
    vector<vector<pair<ll,ll>>> edges(300);
    for (int i = 0; i < m; i++) {
        ll p,q,c;
        std::cin >> p>>q>>c;
        p--;q--;
        edges[p].push_back({q,c});
    }
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(300,vector<ll>(k+1,0)));
    for (int i = 0; i < 300; i++) {
        dp[0][i][0] = 1;
    }
    
    for (int i = 0; i < n-1; i++) {
        for (int j = 0; j < 300; j++) {
            for (auto e : edges[j]) {
                for (int ii = 0; ii <= k; ii++) {
                    if(ii-e.second>=0) dp[i+1][e.first][ii] += dp[i][j][ii-e.second];
                    dp[i+1][e.first][ii] %= MOD;
                }
            }
        }
    }
    
    ll ans = 0;
    for (int i = 0; i < 300; i++) {
        ans += dp[n-1][i][k];
        ans %= MOD;
    }
    
    std::cout << ans << std::endl;
}
0