bzoj 1560 [JSOI2009]火星藏宝图

1560: [JSOI2009]火星藏宝图
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 844 Solved: 412
[Submit][Status][Discuss]
Description

这里写图片描述

Sample Input

4 10

1 1 20

10 10 10

3 5 60

5 3 30

Sample Output

-4


【分析】
狂暴9000ms+卡过
http://blog.csdn.net/vmurder/article/details/43029513


【代码】

//bzoj 1560 [JSOI2009]火星藏宝图
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 1e9+7
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=200005;
int n,m;
ll dp[1005],pos[1005];
struct node {int x,y,c;} a[mxn];
inline bool comp(node u,node v)
{
    return (u.x==v.x)?u.y<v.y:u.x<v.x;
}
int main()
{
    int i,j;
    memset(dp,-0x3f,sizeof dp);
    scanf("%d%d",&n,&m);
    fo(i,1,n)
      scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].c);
    sort(a+1,a+n+1,comp);
    pos[1]=1,dp[1]=a[1].c;
    fo(i,2,n)
    {
        ll tmp=-inf;
        fo(j,1,a[i].y) if(pos[j])
          tmp=max(tmp,dp[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,dp[a[i].y]=tmp+a[i].c;
    }
    printf("%lld\n",dp[m]);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值