BZOJ 1560 [JSOI2009] 火星藏宝图
来源:互联网 发布:淘宝 冰毒 编辑:程序博客网 时间:2024/05/16 06:09
Description
Input
Output
Sample Input
4 10
1 1 20
10 10 10
3 5 60
5 3 30
1 1 20
10 10 10
3 5 60
5 3 30
Sample Output
-4
HINT
Source
JSOI2009Day2
神奇的DP~
类似于斜率优化的做法,先将所有点按照先x后y的顺序排序,再按顺序DP。用pos[i]表示第i列目前的最低位置,f[i]表示第i列目前的最大值。
不需要开long long;把(1,1)加入到数组中排序会WA,不知道是为什么~
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int n,m,pos[1001],f[1001],now;struct node{int x,y,val;}a[200001];bool operator < (node u,node v){return u.x==v.x ? u.y<v.y:u.x<v.x;}int read(){int x=0,f=1;char ch=getchar();while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}int main(){n=read();m=read();a[1]=(node){m,m,0};n++;for(int i=2;i<=n;i++) a[i].x=read(),a[i].y=read(),a[i].val=read();sort(a+1,a+n+1);pos[1]=1;for(int i=1;i<=n;i++){now=-0x7fffffff;for(int j=1;j<=a[i].y;j++) if(pos[j]) now=max(now,f[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;f[a[i].y]=now+a[i].val;}printf("%d\n",f[m]);return 0;}
阅读全文
1 0
- bzoj 1560 [JSOI2009]火星藏宝图
- BZOJ 1560 [JSOI2009] 火星藏宝图
- BZOJ 1560 JSOI2009 火星藏宝图 动态规划
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- [BZOJ]1560: [JSOI2009]火星藏宝图 DP
- 1560: [JSOI2009]火星藏宝图
- 1560: [JSOI2009]火星藏宝图
- BZOJ1560: [JSOI2009]火星藏宝图
- bzoj1560 [JSOI2009]火星藏宝图
- bzoj1560: [JSOI2009]火星藏宝图
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- 【BZOJ1560】[JSOI2009]火星藏宝图【DP】
- 【BZOJ1560】【JSOI2009】火星藏宝图 动规
- bzoj1560 [JSOI2009]火星藏宝图(dp+贪心)
- bzoj 1452: [JSOI2009]Count
- bzoj 1452 [JSOI2009]Count
- BZOJ 1452 [JSOI2009]Count
- BZOJ 1452 [JSOI2009] Count
- fasttext使用笔记
- HNCU1323: 算法2-1:集合union
- oracle 如何查看日志?
- LeetCode 405. Convert a Number to Hexadecimal (进制转换,移位运算)
- Python笔记002——错误TypeError: 'str' does not support the buffer interface
- BZOJ 1560 [JSOI2009] 火星藏宝图
- /usr/bin/ld: 找不到 -lopencv_dep_cudart
- python 列表操作 及 使用方法
- 前端开发者必备google插件
- Matlab中图形标记
- JS实例操作QQ空间自动点赞方法
- 您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用
- 启动MyEclispe时出现 JVM terminated. exit code=-1的问题,无法启动。
- 第十五周:( LeetCode600) Non-negative Integers without Consecutive Ones(c++)