BZOJ 1560 [JSOI2009] 火星藏宝图
2017-06-01 16:36
483 查看
Description
![](http://www.lydsy.com/JudgeOnline/images/1560_1.jpg)
Input
![](http://www.lydsy.com/JudgeOnline/images/1560_2.jpg)
Output
![](http://www.lydsy.com/JudgeOnline/images/1560_3.jpg)
Sample Input
4 101 1 20
10 10 10
3 5 60
5 3 30
Sample Output
-4HINT
![](http://www.lydsy.com/JudgeOnline/images/1560_4.jpg)
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; }
相关文章推荐
- bzoj 1560 [JSOI2009]火星藏宝图
- BZOJ 1560 JSOI2009 火星藏宝图 动态规划
- 【BZOJ1560】[JSOI2009]火星藏宝图【DP】
- [BZOJ]1560: [JSOI2009]火星藏宝图 DP
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- 【BZOJ1560】【JSOI2009】火星藏宝图 动规
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- bzoj1560 [JSOI2009]火星藏宝图(dp+贪心)
- bzoj1560: [JSOI2009]火星藏宝图
- 【BZOJ1560】【JSOI2009】火星藏宝图 [DP]
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- bzoj1560:[JSOI2009]火星藏宝图(斜率优化)
- bzoj1560 [JSOI2009]火星藏宝图
- 1560: [JSOI2009]火星藏宝图
- 1560: [JSOI2009]火星藏宝图
- BZOJ 1560 火星藏宝图(DP)
- BZOJ1560: [JSOI2009]火星藏宝图
- BZOJ 1560 火星藏宝图(DP)
- BZOJ1559 [JSOI2009]密码 【AC自动机 + 状压dp】
- [bzoj1452][JSOI2009]Count_树状数组