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;
const int INF = 500000001;
struct T
{
int nxt;
int stay;
};
void addup(int &a, int b)
{
a = min(INF, a + b);
}
int main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int n, m, h;
cin >> n >> m >> h;
vector<vector<T>> g(n);
vector<int> sol(m);
for (int i = 0; i < n - 1; i++)
{
g[i].resize(h);
for (int j = 0; j < h; j++)
{
cin >> g[i][j].nxt >> g[i][j].stay;
}
}
vector<vector<int>> dp(n, vector<int> (m, 0));
dp[0][0] = 1;
for (int i = 0; i < n; i++)
{
for (int cur = 0; cur <= m; cur++)
{
for (auto &it : g[i])
{
for (int stay = it.stay; cur + stay < m; stay++)
{
addup(dp[it.nxt][cur + stay], dp[i][cur]);
}
}
}
}
for (int i = 0; i < m; i++)
{
cout << dp[n - 1][i] << " ";
}
cout << "\n";
return 0;
}
# | 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... |