码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1560 火星藏宝图(DP)

时间:2014-06-23 08:02:25      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   http   tar   com   

题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1560

题意:

bubuko.com,布布扣

思路:f[i]表示到达i的最大收益。这样是 O(n^2)的。我们考虑,由于转移的条件,a^2+b^2<(a+b)^2,因此对于三个点A、B、C。若A能到B,B能到C,那么A也能到C, 但是不如经过B更好。因此,我们记录到达第j列最靠下的i即可。那么转移(x,y)时,用记录的前y列即可。

 

struct node
{
    int x,y,w;
};


node a[N];
int b[1005],c[1005],n,m;


int cmp(node a,node b)
{
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}


int dis(int x1,int y1,int x2,int y2)
{
    return sqr(x1-x2)+sqr(y1-y2);
}


int main()
{
    RD(n,m);
    int i,j;
    FOR1(i,n) RD(a[i].x,a[i].y,a[i].w);
    sort(a+1,a+n+1,cmp);
    int x,y,w,temp;
    FOR1(i,m) b[i]=-INF;
    b[1]=a[1].w; c[1]=1;
    for(i=2;i<=n;i++)
    {
        x=a[i].x; y=a[i].y; w=a[i].w;
        temp=-INF;
        for(j=1;j<=y;j++) upMax(temp,b[j]-dis(x,y,c[j],j));
        temp+=w;
        b[y]=temp; c[y]=x;
    }
    PR(temp);
}

 

 

 

 

BZOJ 1560 火星藏宝图(DP),布布扣,bubuko.com

BZOJ 1560 火星藏宝图(DP)

标签:style   class   blog   http   tar   com   

原文地址:http://www.cnblogs.com/jianglangcaijin/p/3799482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!