【BZOJ1560】[JSOI2009]火星藏宝图【DP】
来源:互联网 发布:淘宝客服选择题 编辑:程序博客网 时间:2024/05/09 05:57
【题目链接】
可以证明,如果有A->B->C,那么A->C一定不是最优的。然后搞一搞就行啦。
/* Telekinetic Forest Guard */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 200005, maxm = 1005, inf = 0x3f3f3f3f;int n, m, dp[maxn], now[maxm];struct _point {int x, y, w;bool operator < (const _point &a) const {return y != a.y ? y < a.y : x < a.x;}} p[maxn];inline int iread() {int f = 1, x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';return f * x;}inline int dis(_point &a, _point &b) {return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}int main() {n = iread(); m = iread();for(int i = 1; i <= n; i++) p[i].x = iread(), p[i].y = iread(), p[i].w = iread();sort(p + 1, p + 1 + n);memset(dp, -0x3f, sizeof(dp));dp[1] = p[1].w;for(int i = 1; i <= n; i++) {for(int j = 1; j <= p[i].x; j++) if(now[j])dp[i] = max(dp[i], dp[now[j]] - dis(p[now[j]], p[i]) + p[i].w);now[p[i].x] = i;}printf("%d\n", dp[n]);return 0;}
0 0
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- 【BZOJ1560】[JSOI2009]火星藏宝图【DP】
- bzoj1560 [JSOI2009]火星藏宝图(dp+贪心)
- BZOJ1560: [JSOI2009]火星藏宝图
- bzoj1560 [JSOI2009]火星藏宝图
- bzoj1560: [JSOI2009]火星藏宝图
- 【BZOJ1560】【JSOI2009】火星藏宝图 动规
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- [BZOJ]1560: [JSOI2009]火星藏宝图 DP
- 1560: [JSOI2009]火星藏宝图
- 1560: [JSOI2009]火星藏宝图
- bzoj 1560 [JSOI2009]火星藏宝图
- BZOJ 1560 [JSOI2009] 火星藏宝图
- BZOJ 1560 JSOI2009 火星藏宝图 动态规划
- bzoj 1559: [JSOI2009]密码 AC自动机+状压dp
- [BZOJ1559]-[JSOI2009]密码-补全AC自动机+状压dp
- [BZOj]1559 [JSOI2009] 密码 AC自动机 + 状压DP
- bzoj1559 [JSOI2009]密码(AC自动机+状压DP)
- 消息通讯
- redis-集合
- ViewPager系列之ViewPager一屏显示多个子页面
- 设计模式(二十)职责链模式
- Eratosthenes筛法求素数
- 【BZOJ1560】[JSOI2009]火星藏宝图【DP】
- 安卓倒计时 CountdownTimer进行倒计时
- First Blog!
- xpath选择当前结点的子节点
- Java并发包探秘 (一) ConcurrentLinkedQueue
- s2s3m3架构整合
- java socket 编程
- xcode编写代码没有提示或者感觉那里被不小心设置了
- 判断一棵树是否是另一棵树的子树(C语言版)