結果

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll dp[303][303][303];
int main()
{
    int n, m, k; cin>>n>>m>>k;
    int p[303], q[303], c[303];
    vector<P> g[303];
    for(int i=0; i<m; i++){
        cin>>p[i]>>q[i]>>c[i];
        p[i]--; q[i]--;
        g[p[i]].push_back({q[i], c[i]});
        dp[1][q[i]][c[i]]++;
    }
    for(int i=1; i<n-1; i++){
        for(int j=0; j<300; j++){
            if(g[j].empty()) continue;
            for(int l=0; l<=k; l++){
                if(dp[i][j][l]==0) continue;
                for(auto q:g[j]){
                    int y=q.first;
                    if(l+q.second<=k){
                        (dp[i+1][y][l+q.second]+=dp[i][j][l])%=MOD;
                    }
                }
            }
        }
    }
    ll ans=0;
    for(int i=0; i<300; i++){
        (ans+=dp[n-1][i][k])%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0