# bzoj1560 [JSOI2009]火星藏宝图

http://www.elijahqi.win/archives/1313

Description

Input

Output

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

(x+y)^2>=x^2+y^2

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 220000
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
return *S++;
}
int x=0,f=1;char ch=gc();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x*f;
}
struct node{int x,y,z;}data[N];
struct node1{long long max,pos;node1(){max=-0x7f7f7f7f;}}column[1100];
inline bool cmp(node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
inline int calc(int x,int y){
return (data[x].x-data[y].x)*(data[x].x-data[y].x)+(data[x].y-data[y].y)*(data[x].y-data[y].y);
}
int n,m;long long dp[N];
int main(){
freopen("bzoj1560.in","r",stdin);
data[++n].x=1;data[n].y=1;data[++n].x=m;data[n].y=m;
sort(data+1,data+n+1,cmp);memset(dp,128,sizeof(dp));dp[1]=0;column[1].pos=1;column[1].max=0;
//  for (int i=1;i<=n;++i) printf("%d %d\n",data[i].x,data[i].y);
int st=1;
for (int i=1;i<=2;++i){
if (data[i].x==1&&data[i].y&&!data[i].z)dp[i]=0;
if (data[i].x==1&&data[i].y==1&&data[i].z){
dp[i]=data[i].z;column[1].pos=i;column[1].max=data[i].z;st=i;
}
}
//  for (int i=1;i<=n;++i) printf("%d ",dp[i]);printf("\n");
for (int i=st+1;i<=n;++i){
for (int j=1;j<=data[i].y;++j)
if (column[j].pos) dp[i]=max(dp[i],dp[column[j].pos]-calc(column[j].pos,i)+data[i].z);
column[data[i].y].max=dp[i],column[data[i].y].pos=i;
}
printf("%lld\n",dp[n]);
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120