BZOJ3928 [Cerc2014] Outer space invaders
第一眼,我勒个去。。。然后看到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;
}
BZOJ3928 [Cerc2014] Outer space invaders的更多相关文章
- 2018.10.25 bzoj3928: [Cerc2014] Outer space invaders(区间dp)
传送门 区间dpdpdp好题. 首先肯定需要把坐标离散化. 然后在数轴上面区间dpdpdp. 对于当前区间,区间中最大的数一定会被选. 于是我们记f[i,j]f[i,j]f[i,j]表示所有左端点在i ...
- [BZOJ3928/4048]Outer space invaders
[BZOJ3928/4048]Outer space invaders 题目大意: 有\(n(n\le300)\)个物品,第\(i\)个物品会在\(a_i\sim b_i\)时刻出现,且离你的距离为\ ...
- BZOJ.3928.[CERC2014]Outer space invaders(区间DP)
BZOJ3928 双倍经验BZOJ4048 Codeforces GYM100543 L \(Description\) \(Solution\) 考虑出现时间在\([l,r]\)内的敌人,设最远的敌 ...
- bzoj 3928: [Cerc2014] Outer space invaders
$f[i][j]$表示消灭起始时间在$(i,j)$内的外星人所花费的最小代价. 考虑在这个区间内距离最远的外星人h,在他的区间中一定要选一个点要开一炮,而且这一炮可以顺便把其他跨过这个点的敌人消灭,剩 ...
- [CERC2014] Outer space invaders
题目链接 题意 你受到一群外星人的攻击,第 $i$ 个外星人会在 $ai$ 时间出现,与你的距离为 $di$,且必须在 $bi$ 时间前消灭.你有一个区域冲击波器,每次攻击可以设定一个功率 $R$,这 ...
- Codeforces Gym100543L Outer space invaders 区间dp 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543L.html 题目传送门 - CF-Gym100543L 题意 $T$ 组数据. 有 $n ...
- Codeforces Gym100543L:Outer space invaders(区间DP)
题目链接 题意 有n个人,每个人有一个出现时间a和一个开枪时间b和一个距离d,在任意一个时刻,你可以选择炸人,你要炸一个人的花费是和他的距离d,并且所有的已经出现并且还没开枪的和你距离<=d的人 ...
- Space Invaders 太空侵略者
发售年份 1978 平台 街机 开发商 Taito 类型 射击 https://www.youtube.com/watch?v=MU4psw3ccUI
- 区间dp提升复习
区间\(dp\)提升复习 不得不说这波题真的不简单... 技巧总结: 1.有时候转移可以利用背包累和 2.如果遇到类似区间添加限制的题可以直接把限制扔在区间上,每次只考虑\([l,r]\)被\([i, ...
随机推荐
- C#中实现多继承的方法
有一个类叫老虎,还有一个类叫苍蝇.现在新创一个超级老虎类,一种可以飞的老虎,超级老虎由于同时也继承自苍蝇 namespace Interface { //飞的接口 public interface I ...
- 《Linux内核设计的艺术》学习笔记(四)默认段和偏移寄存器
参考书籍:<Intel微处理器> 表1 默认的16位段 + 偏移寻址组合 段 偏移量 特殊用途 CS IP 指令地址 SS SP或BP 堆栈地址 DS BX.DI.SI.8位或16位数 数 ...
- css3 3d学习笔记
几个属性: -webkit-perspective:0;景深(默认0), -webkit-perspective-origin:center center;景深基点(默认中间), -webkit-tr ...
- LTE Module User Documentation(翻译2)——配置LTE MAC 调度器
LTE用户文档 (如有不当的地方,欢迎指正!) 5 配置 LTE MAC 调度器 这里有几种 LTE MAC 调度器用户可以选择.使用下面的代码定义调度器的类型: Ptr<LteHelper ...
- hibernate对象关系实现(三)多对多实现
单向n-n:(catogory-item)一个类别对应多个条目,一个条目对应多个类别 a.以类别类中有条目的集合的引用为例: b.数据库中的体现:建立一个新表,以类别和条目的主键关联的外键做新表的联合 ...
- HDU5829 NTT
以下这份代码并没有过.但感觉没有问题.不是蜜汁WA就是蜜汁T. #include <cstdio> #include <iostream> #include <cstri ...
- awt组件中文乱码Intellij解决
-Dfile.encoding=GB18030 -Dfile.encoding=GB18030
- Linux系统/etc/init.d目录
理解Linux系统/etc/init.d目录和/etc/rc.local脚本 http://blog.csdn.net/acs713/article/details/7322082 Linux文件目录 ...
- (四)linux常用命令
1.在vim下要查找特定的字符串可按Esc键,然后按/字符串,如/DFGE 2.在vim下要显示行数:set nu
- intersection-of-two-arrays-ii
https://leetcode.com/problems/intersection-of-two-arrays-ii/ class Solution { public: vector<int& ...