bzoj 1560 [JSOI2009]火星藏宝图(DP)
1560: [JSOI2009]火星藏宝图
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 647 Solved: 309
[Submit][Status][Discuss]
Description

Input

Output

Sample Input
1 1 20
10 10 10
3 5 60
5 3 30
Sample Output
HINT

Source
【代码】
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn = +;
const int maxm = +;
const int INF = 1e9; struct node{
int x,y,p;
bool operator<(const node& rhs) const{
return (x<rhs.x)||(x==rhs.x && y<rhs.y);
}
}a[maxm]; int pos[maxn],n,m;
LL d[maxn]; int read(int& x) {
char c=getchar();
while(!isdigit(c)) c=getchar();
x=;
while(isdigit(c)) x=x*+c-'',c=getchar();
} int main() {
scanf("%d%d",&n,&m);
n+=;
a[].x=a[].y=;
a[].x=a[].y=m;
for(int i=;i<=n;i++)
read(a[i].x),read(a[i].y),read(a[i].p);
sort(a+,a+n+);
pos[]=;
for(int i=;i<=n;i++) {
LL tmp=-INF;
for(int j=;j<=a[i].y;j++) if(pos[j])
tmp=max(tmp,d[j]-(a[i].y-j)*(a[i].y-j)-(a[i].x-pos[j])*(a[i].x-pos[j]));
pos[a[i].y]=a[i].x , d[a[i].y]=tmp+a[i].p;
}
printf("%lld\n",d[m]);
return ;
}
bzoj 1560 [JSOI2009]火星藏宝图(DP)的更多相关文章
- 【BZOJ1560】[JSOI2009]火星藏宝图(贪心,动态规划)
[BZOJ1560][JSOI2009]火星藏宝图(贪心,动态规划) 题面 BZOJ 洛谷 题解 既然所有的位置的权值都大于\(0\),那么就可以直接贪心,按照行为第一关键字,列为第二关键字,来转移. ...
- 【BZOJ1560】【JSOI2009】火星藏宝图 [DP]
火星藏宝图 Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input Output Samp ...
- BZOJ 1560 火星藏宝图(DP)
思路:发现如果从A能到B,B能到C,那么一定A能到C,且根据不等式:A^2+B^2<=(A+B)^2,而且权值没有负数,因此经过B比不经过B要优,因此,我们从左上到右下做,每一列,我们只记录之前 ...
- [luogu4056 JSOI2009] 火星藏宝图 (贪心 dp)
传送门 Solution 一个显然的贪心:选的点数越多越好.这个随便推推就知道了. 那么我们就贪心的从一列上挑最靠下的转移 直接转移不斜率优化复杂度\(O(nm)\),吸一口O2过了... Code ...
- bzoj1560:[JSOI2009]火星藏宝图(斜率优化)
题目描述 在火星游玩多日,jyy偶然地发现了一张藏宝图.根据藏宝图上说法,宝藏被埋藏在一个巨大的湖里的N个岛上(2<=N<=200,000).为了方便描述,地图把整个湖划分成M行M列(1& ...
- 【[JSOI2009]火星藏宝图】
这里是\(sb\)的\(O(nm)\)做法 上一篇题解里写的\(O(nm)\)做法并没有看懂,我真是好菜啊 这是一个用了斜率优化,但是复杂度仍然是\(O(nm)\)的做法 我们还是先写出简单的\(dp ...
- bzoj1560: [JSOI2009]火星藏宝图
考虑到一个性质,A到B的距离一定不小于A到C再到B的距离,因为能够到达这三个点不可能构成锐角三角形 对于当前点的更新只需要找那些无法经过其它点再到当前点的点,相当于是一个y坐标单调减的上凸包,随便维护 ...
- BZOJ 1444:[JSOI2009]有趣的游戏
BZOJ 1444:[JSOI2009]有趣的游戏 题目链接 首先我们建出Trie图,然后高斯消元. 我们设\(f_i\)表示经过第\(i\)个点的期望次数: \[ f_x=\sum i\cdot p ...
- [BZOJ 2257][JSOI2009]瓶子和燃料 题解(GCD)
[BZOJ 2257][JSOI2009]瓶子和燃料 Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子 ...
随机推荐
- struts_ognl详解
- mysql locktables
SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, TIMESTAMPDIFF( ...
- 同一台电脑上安装两个tomcat服务器
1.下载免安装版tomcat,解压成tomcat1.tomcat2: 2.修改tomcat2中conf下server.xml文件如下: <Server port="8005" ...
- iOS远程消息推送自我整理版
@interface AppDelegate () <UIApplicationDelegate> @end @implementation AppDelegate - (BOOL)app ...
- C# 多线程详解
1.使用多线程的几种方式 (1)不需要传递参数,也不需要返回参数 ThreadStart是一个委托,这个委托的定义为void ThreadStart(),没有参数与返回值. 复制代码 代码如下: cl ...
- 64位 CentOS NDK 编译 FFMPEG
64位 CentOS NDK 编译 FFMPEG 一. 参考文章: http://www.cnblogs.com/baopu/p/4733029.html http://www.c ...
- 初试ubuntu14.4问题集锦
接触Linux系统也好长时间了,但每次都是浅尝则止.前几天突发兴趣,想认真地学习一下这个名扬天下的稳定的操作系统.于是试着装了一下炒作的最凶的Ubuntu. 安装的Ubuntu系统版本为14.04. ...
- directsound 应用实例
sdk里边有个文件夹Samples\C++\XInput\AudioController这个就是
- input file文件上传样式
<style> .file-group { position: relative; width: 200px; height: 80px; ...
- Flask_SqlAlchemy 1215, 'Cannot add f oreign key constraint'
Flask_SqlAlchemy 1215, 'Cannot add f oreign key constraint'报错 sqlalchemy.exc.IntegrityError: (pymysq ...