結果

問題 No.1111 コード進行
ユーザー kappybarkappybar
提出日時 2020-07-10 22:42:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 4,301 ms
コンパイル使用メモリ 241,568 KB
実行使用メモリ 225,408 KB
最終ジャッジ日時 2024-04-19 17:56:21
合計ジャッジ時間 14,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
225,408 KB
testcase_01 AC 174 ms
225,152 KB
testcase_02 AC 172 ms
225,280 KB
testcase_03 AC 171 ms
225,280 KB
testcase_04 AC 172 ms
225,280 KB
testcase_05 AC 171 ms
225,408 KB
testcase_06 AC 173 ms
225,280 KB
testcase_07 AC 173 ms
225,152 KB
testcase_08 AC 173 ms
225,280 KB
testcase_09 AC 179 ms
225,280 KB
testcase_10 AC 173 ms
225,280 KB
testcase_11 AC 171 ms
225,280 KB
testcase_12 AC 173 ms
225,280 KB
testcase_13 AC 175 ms
225,280 KB
testcase_14 AC 179 ms
225,152 KB
testcase_15 AC 174 ms
225,280 KB
testcase_16 AC 171 ms
225,280 KB
testcase_17 AC 175 ms
225,280 KB
testcase_18 AC 173 ms
225,280 KB
testcase_19 AC 171 ms
225,280 KB
testcase_20 AC 173 ms
225,152 KB
testcase_21 AC 173 ms
225,280 KB
testcase_22 AC 173 ms
225,280 KB
testcase_23 AC 173 ms
225,280 KB
testcase_24 AC 176 ms
225,408 KB
testcase_25 AC 174 ms
225,152 KB
testcase_26 AC 178 ms
225,152 KB
testcase_27 AC 175 ms
225,280 KB
testcase_28 AC 188 ms
225,280 KB
testcase_29 AC 174 ms
225,152 KB
testcase_30 AC 186 ms
225,280 KB
testcase_31 AC 171 ms
225,152 KB
testcase_32 AC 201 ms
225,280 KB
testcase_33 AC 207 ms
225,280 KB
testcase_34 AC 174 ms
225,280 KB
testcase_35 AC 175 ms
225,152 KB
testcase_36 AC 174 ms
225,152 KB
testcase_37 AC 177 ms
225,280 KB
testcase_38 AC 199 ms
225,280 KB
testcase_39 AC 234 ms
225,152 KB
testcase_40 AC 268 ms
225,280 KB
testcase_41 AC 179 ms
225,152 KB
testcase_42 AC 171 ms
225,408 KB
testcase_43 AC 234 ms
225,280 KB
testcase_44 AC 170 ms
225,280 KB
testcase_45 AC 170 ms
225,280 KB
testcase_46 AC 169 ms
225,280 KB
testcase_47 AC 169 ms
225,408 KB
testcase_48 AC 178 ms
225,280 KB
testcase_49 AC 171 ms
225,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n,m,k;
vector<vector<P>> graph(305,vector<P>());
ll dp[305][305][305] = {-1};

ll dfs(int i,int cnt,int cost){
    if(dp[i][cnt][cost]>=0) return dp[i][cnt][cost];
    if(cnt==0){
        if(cost==0) return 1;
        else return 0;
    }

    ll res = 0;
    rep(j,graph[i].size()){
        if(cost-graph[i][j].first<0) continue;
        ll p = dfs(graph[i][j].second,cnt-1,cost-graph[i][j].first);
        res = (res + p)%MOD;
    }

    return dp[i][cnt][cost] = res;
}

int main(){
    rep(i,305)rep(j,305)rep(k,305) dp[i][j][k] = -1;
    cin >> n >> m >> k;
    rep(i,m){
        int p,q,c;
        cin >> p >> q >> c;
        graph[p].push_back(P(c,q));
    }
    for(int i=1;i<305;i++) graph[0].push_back(P(0,i));

    cout << dfs(0,n,k) << endl;
    return 0;
}
0