# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397861 | maomao90 | Journey (NOI18_journey) | C++14 | 78 ms | 35488 KiB |
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;
typedef pair <int, int> ii;
#define INF 500000001
int n, m, h;
vector <ii> adjList[10005];
long long memo[10005][405];
long long dp(int index, int rem) {
if (index >= n - 1) {
if (rem == 0) return 1;
else return 0;
}
if (rem < 0) return 0;
if (memo[index][rem] != -1) return memo[index][rem];
long long cur = 0;
cur += dp(index, rem - 1);
if (cur >= INF) return memo[index][rem] = INF;
for (ii vw : adjList[index]) {
int v, w; tie(v, w) = vw;
cur += dp(v, rem - w);
if (cur >= INF) return memo[index][rem] = INF;
}
return memo[index][rem] = cur;
}
int main() {
scanf("%d%d%d", &n, &m, &h);
for (int i = 0; i < n - 1; i++) {
for (int jj = 0; jj < h; jj++) {
int j, k; scanf("%d%d", &j, &k);
if (j <= i) continue;
adjList[i].emplace_back(j, k);
}
}
memset(memo, -1, sizeof memo);
for (int i = 0; i < m; i++) {
printf("%lld ", dp(0, i));
}
printf("\n");
return 0;
}
Compilation message (stderr)
# | 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... |