Idea: found that if from a can to b,b can to C, then must a can to C, and according to the inequality: a^2+b^2<= (a+b) ^2, and the weight of no negative, so after B than not through the B to excellent, so we from the top left to the right down, each column, We only record the information of the bottom position that we have done before, and then we look for the best from the first few columns in this position.
1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 #definell Long Long7 #defineINF 9999999998 structpoint{9 intx,y,w;Ten Point () {} OnePoint (intX0,inty0): X (x0), Y (y0) {} A}a[200005]; - intn,m,b[200005],c[200005]; - intRead () { the intt=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; ch=GetChar ();} - while(ch<='9'&&ch>='0') {t=t*Ten+ch-'0'; ch=GetChar ();} - returnt*F; + } - BOOLCMP (Point p1,point p2) { + if(p1.x!=p2.x)returnp1.x<p2.x; A returnp1.y<p2.y; at } - intSqrintx) { - returnx*x; - } - intdis (point p1,point p2) { - returnSqr (p1.x-p2.x) +SQR (p1.y-p2.y); in } - intMain () { toN=read (); m=read (); + for(intI=1; i<=n;i++) A[i].x=read (), A[i].y=read (), a[i].w=read (); -Std::sort (A +1, A +1+n,cmp); the for(intI=1; i<=m;i++) b[i]=-inf; *b[1]=a[1].W; $c[1]=1;Panax Notoginseng inttmp; - for(intI=2; i<=n;i++){ the intx=a[i].x,y=a[i].y,w=A[I].W; +tmp=-inf; A for(intj=1; j<=y;j++) theTmp=std::max (tmp,b[j]-Dis (point (x, y), point (C[j],j))); +tmp+=W; -b[y]=tmp;c[y]=x; $ } $printf"%d\n", TMP); -}
Bzoj 1560 Mars Treasure Map (DP)