gym 100543 CERC 2014 L Outer space invaders
来源:互联网 发布:尚硅谷大数据视频 编辑:程序博客网 时间:2024/06/11 22:18
Problem
Central Europe Regional Contest 2014
vjudge.net/problem/Gym-100543L
Meaning
有 n 个敌人,第 i 个将在
你有一种炸弹,可随意设置爆炸范围 R,引爆后在 R 以内的、已经出现的敌人会被炸死,消耗 R 格燃料。
要在任何一个敌人出现后、开枪前([
Analysis
当时的错误想法:先按(dp[i]:及时搞掂前 i 个敌人的最小消耗
对于最后一个敌人 i,可能跟着最后的若干的敌人一起被炸,于是转移: dp[i] = min { dp[j] + cost( j+1 , i ) | 0<=j<i }
其中 cost( j+1 , i )
是从第 j+1 个到第 i 个敌人里最远的距离(因为是一起炸),且要满足条件:min {
但这样是错的,排序有毒,有考虑不到的情况,如反例:
131 4 102 2 13 4 11
这样是要 1、3 一起炸,2 单独炸。
官方题解是把敌人理解成一条条从(
于是把所有时刻(a 和 b)离散化后,用区间dp: dp[s][e]:与所有完全包含在时间段 [ s , e ] 内的所有横线的最小竖线长度和
(暂时没完全理解 :( …)
Accepted Code
#include <cstdio>#include <algorithm>using namespace std;const int N = 300, D = 10000, BIG = N * D;struct node{ int a, b, d;} al[N];int ts[N<<1|1], dp[N+1<<1][N+1<<1] = {{0}};int main(){ int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); int m = 0; for(int i = 0; i < n; ++i) { scanf("%d%d%d", &al[i].a, &al[i].b, &al[i].d); ts[++m] = al[i].a; ts[++m] = al[i].b; } sort(ts + 1, ts + m + 1); m = unique(ts + 1, ts + m + 1) - ts - 1; for(int i = 0; i < n; ++i) { al[i].a = lower_bound(ts + 1, ts + m + 1, al[i].a) - ts; al[i].b = lower_bound(ts + 1, ts + m + 1, al[i].b) - ts; } for(int w = 0; w < m; ++w) for(int s = 1; s + w <= m; ++s) { int e = s + w, id = -1; for(int i = 0; i < n; ++i) if(s <= al[i].a && al[i].b <= e && (id == -1 || al[i].d > al[id].d)) id = i; if(id == -1) { dp[s][e] = 0; continue; } dp[s][e] = BIG; for(int k = al[id].a; k <= al[id].b; ++k) dp[s][e] = min(dp[s][e], dp[s][k-1] + al[id].d + dp[k+1][e]); } printf("%d\n", dp[1][m]); } return 0;}
Wrong DP
#include <cstdio>#include <algorithm>using namespace std;const int N = 300;struct node{ int a, b, d; bool operator < (const node &rhs) const { return a == rhs.a ? b < rhs.b : a < rhs.a; }} arr[N+10];int dp[N+10];int main(){ int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); for(int i=1; i<=n; ++i) scanf("%d%d%d", &arr[i].a, &arr[i].b, &arr[i].d); sort(arr + 1, arr + n + 1); dp[0] = 0; for(int i=1; i<=n; ++i) { dp[i] = dp[i-1] + arr[i].d; int r = arr[i].d; for(int j=i-1; j; --j) { if(arr[j].b < arr[i].a) break; r = max(r, arr[j].d); dp[i] = min(dp[i], dp[j-1] + r); } } printf("%d\n", dp[n]); } return 0;}
阅读全文
0 0
- gym 100543 CERC 2014 L Outer space invaders
- Cerc2014 Outer space invaders
- 【CERC2014】【BZOJ3928】【BZOJ4048】Outer space invaders
- BZOJ4048/3928 [Cerc2014] Outer space invaders
- CFgym:Outer space invaders(区间dp)
- BZOJ3928: [Cerc2014] Outer space invaders(区间DP)
- CERC 2014 L题 区间dp 思维
- 2014-2015 ACM-ICPC, Central Europe Regional Contest (CERC 14) [Gym-100543G]
- [2-SAT 构造] Codeforces Gym 101173 CERC 16 L. Lost Logic
- GYM CERC 16 K Key Knocking 构造
- Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks
- Gym CERC 16 F Free Figuriness 思维+模拟
- Wheels(bfs遍历,CERC 2014)
- [分治 杂题] Codeforces Gym 101173 CERC 16 G & BZOJ 4792 Geohash Grid
- Gym 100187L - Ministry of Truth
- Gym 100703L Many questions 水题
- Gym 100814L Candy Jars 博弈论
- Gym 100851L Landscape Improved(二分+脑洞)
- Gym
- JDK 1.8之 HashMap 源码分析
- PAT (Advanced Level) Practise 1031 Hello World for U (20)
- Android架构设计之MVP分析
- git 的使用
- gym 100543 CERC 2014 L Outer space invaders
- 机器学习-学习笔记 支持向量机
- Spring 4.0 学习日记(1) --IOC 控制反转概念解释
- PAT (Advanced Level) Practise 1032 Sharing (25)
- 不要重新定义继承来的非虚函数
- PHP实现无限极分类的两种方式,递归和引用
- 周志华点评机器学习会议
- 关于leveldb源码整理之一
- PAT (Advanced Level) Practise 1033 To Fill or Not to Fill (25)