-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf 313d.cpp
More file actions
40 lines (36 loc) · 814 Bytes
/
cf 313d.cpp
File metadata and controls
40 lines (36 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX_N = 307;
typedef long long ll;
const ll INF = 1LL<<61;
int n, m, k;
ll w[MAX_N][MAX_N], dp[MAX_N][MAX_N];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
dp[i][j] = w[i][j] = INF;
}
}
for (int i = 1; i <= m; ++i) {
int l, r;
ll c;
scanf("%d%d%I64d", &l, &r, &c);
for (int j = l; j <= r; ++j) {
w[l][j] = min(w[l][j], c);
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= i; ++j) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
for (int k = 1; k <= j; ++k)
dp[i][j] = min(dp[i][j], dp[i - k][j - k] + w[i - k + 1][i]);
}
}
if (dp[n][k] == INF) puts("-1");
else printf("%I64d\n", dp[n][k]);
return 0;
}