結果

問題 No.1111 コード進行
ユーザー fastmath
提出日時 2020-07-10 21:49:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 169,296 KB
実行使用メモリ 112,896 KB
最終ジャッジ日時 2024-10-11 08:50:17
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 307, MOD = 1000 * 1000 * 1000 + 7;
int dp[N][N][N];
int w[N][N];

vector <int> g[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        w[u][v] = c;
        g[u].app(v);
    }   

    auto add = [&](int &a, int b) {
        a += b;
        if (a >= MOD)
            a -= MOD;
    };   

    for (int i = 1; i <= 300; ++i)
        dp[1][i][0] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int u = 1; u <= 300; ++u) {
            for (int sum = 0; sum <= k; ++sum) {

                int &x = dp[i][u][sum];
                x %= MOD;
                if (x == 0)
                    continue;

                //cout << i << ' ' << u << ' ' << sum << " : " << dp[i][u][sum] << endl;

                for (int v : g[u]) {
                    if (sum + w[u][v] <= k) {
                        add(dp[i+1][v][sum+w[u][v]], x);
                    }            
                }   
            }
        }   
    }
    
    int ans = 0;
    for (int i = 1; i <= 300; ++i)
        add(ans, dp[n][i][k]);
    cout << ans << endl;
}
0