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;
}