第一眼,我勒个去。。。然后看到n ≤ 300的时候就2333了
首先把时间离散化,则对于一个时间的区间,可以知道中间最大的那个一定要被选出来,然后把区间分成左右两份
于是区间DP就好了,注意用左开右开的区间比较方便2333
如果暴力找区间内最大值是O(n3)的,当然st表就是O(n2logn)的了。。。不过st表辣么难蒟蒻根本不会QAQQQ
/**************************************************************
Problem: 3928
User: rausen
Language: C++
Result: Accepted
Time:1820 ms
Memory:2248 kb
****************************************************************/ #include <cstdio>
#include <algorithm> using namespace std;
const int N = ;
const int inf = 1e9; inline int read(); struct data {
int st, ed, h;
data(int _s = , int _e = , int _h = ) : st(_s), ed(_e), h(_h) {} inline void get() {
st = read(), ed = read(), h = read();
}
} a[N]; int n, tot;
int tmp[N], len;
int f[N][N]; int main() {
int T, H, i, j, k;
T = read();
while (T--) {
n = read();
for (i = ; i <= n; ++i) {
a[i].get();
tmp[i * - ] = a[i].st, tmp[i * ] = a[i].ed;
}
sort(tmp + , tmp + * n + );
tot = unique(tmp + , tmp + * n + ) - tmp - ;
for (i = ; i <= n; ++i) {
a[i].st = lower_bound(tmp + , tmp + tot + , a[i].st) - tmp;
a[i].ed = lower_bound(tmp + , tmp + tot + , a[i].ed) - tmp;
}
tot += ;
for (len = ; len <= tot; ++len)
for (i = ; i <= tot - len; ++i) {
j = i + len, H = -;
for (k = ; k <= n; ++k)
if (i < a[k].st && a[k].ed < j && (H == - || a[H].h < a[k].h)) H = k;
if (H == -) f[i][j] = ;
else for (f[i][j] = inf, k = a[H].st; k <= a[H].ed; ++k)
f[i][j] = min(f[i][j], a[H].h + f[i][k] + f[k][j]);
}
printf("%d\n", f[][tot]);
}
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}