結果

問題 No.1111 コード進行
ユーザー kyoprouno
提出日時 2020-07-10 22:13:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 1,332 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 183,684 KB
実行使用メモリ 359,552 KB
最終ジャッジ日時 2024-10-11 09:31:16
合計ジャッジ時間 7,464 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> p(m),q(m),c(m);
    rep(i,m){
        cin >> p[i] >> q[i] >> c[i];
        p[i]--;
        q[i]--;
    }
    vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(300,vector<ll>(500)));
    rep(i,300){
        dp[0][i][0]=1;
    }
    rep(i,n-1){
        rep(j,m){
            for(ll s=0;s<=k;s++){
                if(s-c[j]>=0){
                    dp[i+1][q[j]][s]+=dp[i][p[j]][s-c[j]];
                    dp[i+1][q[j]][s]%=mod;
                }
            }
        }
        //cout << dp[i+1][0][0] << endl;
    }
    ll ans=0;
    rep(j,300){
        ans+=dp[n-1][j][k];
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}
0