bzoj 1560 [JSOI2009]火星藏宝图(DP)
2016-01-04 20:30
537 查看
1560: [JSOI2009]火星藏宝图
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 647 Solved: 309
[Submit][Status][Discuss]
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【代码】
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; const int maxn = 1000+10; const int maxm = 200000+10; 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=0; while(isdigit(c)) x=x*10+c-'0',c=getchar(); } int main() { scanf("%d%d",&n,&m); n+=2; a[1].x=a[1].y=1; a[2].x=a[2].y=m; for(int i=3;i<=n;i++) read(a[i].x),read(a[i].y),read(a[i].p); sort(a+2,a+n+1); pos[1]=1; for(int i=2;i<=n;i++) { LL tmp=-INF; for(int j=1;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 0; }
相关文章推荐
- 【JavaScript面向对象编程】20160104(对象)
- javascript-前篇
- 欢迎使用CSDN-markdown编辑器
- js html时间控件2
- 【学习笔记javascript设计模式与开发实践(装饰者模式)----15】
- JSON 的解析
- 【学习笔记javascript设计模式与开发实践(中介者模式)----14】
- JavaScript中的函数:闭包,this,高阶函数
- js html/vm时间组件1
- canvas:利用js遍历绘制七巧板
- 学习Javascript闭包(Closure)
- JavaScript事件处理程序 学习笔记
- JavaScript事件处理程序 学习笔记
- HTML DOM 对象_HTML 对象_JavaScript 对象_Browser 对象
- jslearning1
- 实现OC与JS的交互
- 在jsp页面如何获得url参数
- PhantomJS是一个基于WebKit的服务器端JavaScript API
- PhantomJS是一个基于WebKit的服务器端JavaScript API
- 整理阅读:高性能JS