#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <iomanip>
#include <assert.h>
#include <bitset>
//#include "cycle.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
const int MAXN = 1e4+5;
const int MAXM = 405;
const int MAXH = 105;
ll dp[MAXN][MAXM];
int main() {
int n, m, h;
cin >> n >> m >> h;
vector<pair<int, int>> adjList[MAXN];
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < h; j++) {
int a, b;
cin >> a >> b;
if (a <= i) {
continue;
}
adjList[i].push_back({ a, b });
}
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if(i != 0)
dp[i][j + 1] = min(dp[i][j + 1] + dp[i][j], (ll)500000001);
for (auto k : adjList[i]) {
if (j + k.second < m) {
dp[k.first][j + k.second] = min(dp[k.first][j + k.second] + dp[i][j], (ll)500000001);
}
}
}
}
for (int i = 0; i < m; i++) {
cout << dp[n - 1][i] << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
876 KB |
Output is correct |
6 |
Correct |
4 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
876 KB |
Output is correct |
6 |
Correct |
4 ms |
876 KB |
Output is correct |
7 |
Correct |
187 ms |
35436 KB |
Output is correct |
8 |
Correct |
165 ms |
21612 KB |
Output is correct |
9 |
Correct |
32 ms |
3308 KB |
Output is correct |
10 |
Correct |
205 ms |
4688 KB |
Output is correct |