您的位置:首页 > Web前端 > JavaScript

bzoj 1560 [JSOI2009]火星藏宝图(DP)

2016-01-04 20:30 537 查看

1560: [JSOI2009]火星藏宝图

Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 647 Solved: 309
[Submit][Status][Discuss]

Description



Input



Output



Sample Input

4 10

1 1 20

10 10 10

3 5 60

5 3 30

Sample Output

-4

HINT



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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: