bzoj 1560 [JSOI2009]火星藏宝图(DP)
1560: [JSOI2009]火星藏宝图
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 647 Solved: 309
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
4 10
1 1 20
10 10 10
3 5 60
5 3 30
1 1 20
10 10 10
3 5 60
5 3 30
Sample Output
-4
HINT
Source
【代码】
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 6 typedef long long LL; 7 const int maxn = 1000+10; 8 const int maxm = 200000+10; 9 const int INF = 1e9; 10 11 struct node{ 12 int x,y,p; 13 bool operator<(const node& rhs) const{ 14 return (x<rhs.x)||(x==rhs.x && y<rhs.y); 15 } 16 }a[maxm]; 17 18 int pos[maxn],n,m; 19 LL d[maxn]; 20 21 int read(int& x) { 22 char c=getchar(); 23 while(!isdigit(c)) c=getchar(); 24 x=0; 25 while(isdigit(c)) x=x*10+c-'0',c=getchar(); 26 } 27 28 int main() { 29 scanf("%d%d",&n,&m); 30 n+=2; 31 a[1].x=a[1].y=1; 32 a[2].x=a[2].y=m; 33 for(int i=3;i<=n;i++) 34 read(a[i].x),read(a[i].y),read(a[i].p); 35 sort(a+2,a+n+1); 36 pos[1]=1; 37 for(int i=2;i<=n;i++) { 38 LL tmp=-INF; 39 for(int j=1;j<=a[i].y;j++) if(pos[j]) 40 tmp=max(tmp,d[j]-(a[i].y-j)*(a[i].y-j)-(a[i].x-pos[j])*(a[i].x-pos[j])); 41 pos[a[i].y]=a[i].x , d[a[i].y]=tmp+a[i].p; 42 } 43 printf("%lld\n",d[m]); 44 return 0; 45 }
posted on 2016-01-04 20:30 hahalidaxin 阅读(221) 评论(0) 编辑 收藏 举报