This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int n, m, h, vis[10005], dp[10005][405];
vector<pair<int, int> > adj[10005];
void dfs(int u){
if(u == n - 1) return;
vis[u] = true;
for(auto e : adj[u]){
int v = e.ff, w = e.ss;
if(v < u) continue;
if(!vis[v]) dfs(v);
for(int i = w; i < m; i++){
dp[u][i] += dp[v][i - w];
dp[u][i] = min(dp[u][i], 500000001LL);
}
}
for(int i = 1; i < m; i++) {
dp[u][i] += dp[u][i - 1];
dp[u][i] = min(dp[u][i], 500000001LL);
}
}
signed main(){
cin >> n >> m >> h;
for(int u = 0; u < n - 1; u++){
for(int i = 0; i < h; i++){
int v, w; cin >> v >> w;
adj[u].pb({v, w});
}
}
dp[n - 1][0] = 1;
dfs(0);
for(int i = 0; i < m; i++) cout << dp[0][i] << ' ';
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |