Bzoj 1560 Mars Treasure Map (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.