#include <bits/stdc++.h>
using namespace std;
#define int long long int
int n, m, h;
const int N = 10010, M = 410;
int dp[N + 1][M + 1];
vector<vector<pair<int, int>>> graph(N + 1);
void solve(bool testCases = true) {
int T = 1;
if (testCases) cin >> T;
while (T--) {
cin >> n >> m >> h;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < h; j++) {
int a, b;
cin >> a >> b;
if (i >= a) {
continue;
}
graph[a].push_back({i, b});
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
for (auto [child, weight] : graph[i]) {
for (int wt = j - weight; wt >= 0; wt--) {
dp[i][j] += dp[child][wt];
dp[i][j] = min(dp[i][j], 500000001LL);
}
}
}
}
for (int i = 0; i < m; i++) {
cout << dp[n - 1][i];
cout << " ";
}
cout << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve(false);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32860 KB |
Output is correct |
2 |
Correct |
5 ms |
32856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
32860 KB |
Output is correct |
2 |
Correct |
4 ms |
32684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32860 KB |
Output is correct |
2 |
Correct |
5 ms |
32856 KB |
Output is correct |
3 |
Correct |
5 ms |
32860 KB |
Output is correct |
4 |
Correct |
4 ms |
32684 KB |
Output is correct |
5 |
Correct |
18 ms |
32860 KB |
Output is correct |
6 |
Correct |
18 ms |
32860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32860 KB |
Output is correct |
2 |
Correct |
5 ms |
32856 KB |
Output is correct |
3 |
Correct |
5 ms |
32860 KB |
Output is correct |
4 |
Correct |
4 ms |
32684 KB |
Output is correct |
5 |
Correct |
18 ms |
32860 KB |
Output is correct |
6 |
Correct |
18 ms |
32860 KB |
Output is correct |
7 |
Correct |
83 ms |
37892 KB |
Output is correct |
8 |
Correct |
570 ms |
36124 KB |
Output is correct |
9 |
Correct |
864 ms |
33344 KB |
Output is correct |
10 |
Execution timed out |
2041 ms |
35676 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |