【BZOJ1560】【JSOI2009】火星藏宝图 [DP]
2017-05-28 11:05
316 查看
火星藏宝图
Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss]
Description
#include<iostream> #include<string> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> using namespace std; typedef long long s64; const int ONE = 500005; const int INF = 2147483640; int n,m; int pos[ONE]; int f[ONE]; struct power { int x,y,z; }a[ONE]; bool cmp(const power &a, const power &b) { if(a.x != b.x) return a.x < b.x; return a.y < b.y; } int cost(int Ax, int Ay, int Bx, int By) { return (Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By); } int get() { int res=1,Q=1;char c; while( (c=getchar())<48 || c>57 ) if(c=='-')Q=-1; res=c-48; while( (c=getchar())>=48 && c<=57 ) res=res*10+c-48; return res*Q; } int main() { n = get(); m = get(); for(int i=1; i<=n; i++) a[i].x = get(), a[i].y = get(), a[i].z = get(); sort(a+1, a+n+1, cmp); memset(f, -127, sizeof(f)); pos[1] = 1; f[1] = 0; for(int id=1; id<=n; id++) { int x = a[id].x, y = a[id].y; int record = -INF; for(int j=1; j<=y; j++) if(pos[j]) record = max( record, f[j] - cost(pos[j],j, x,y) ); pos[y] = x; f[y] = record + a[id].z; } printf("%d", f[m]); }View Code
相关文章推荐
- bzoj1560 [JSOI2009]火星藏宝图(dp+贪心)
- 【BZOJ1560】[JSOI2009]火星藏宝图【DP】
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
- [BZOJ]1560: [JSOI2009]火星藏宝图 DP
- BZOJ 1560 JSOI2009 火星藏宝图 动态规划
- bzoj 1560 [JSOI2009]火星藏宝图
- bzoj1560:[JSOI2009]火星藏宝图(斜率优化)
- 【BZOJ1560】【JSOI2009】火星藏宝图 动规
- BZOJ 1560 [JSOI2009] 火星藏宝图
- bzoj1560 [JSOI2009]火星藏宝图
- bzoj1560: [JSOI2009]火星藏宝图
- 1560: [JSOI2009]火星藏宝图
- BZOJ 1560 火星藏宝图(DP)
- 1560: [JSOI2009]火星藏宝图
- BZOJ 1560 火星藏宝图(DP)
- [BZOj]1559 [JSOI2009] 密码 AC自动机 + 状压DP
- bzoj1559 [JSOI2009]密码(AC自动机+状压DP)
- BZOJ1444:[Jsoi2009]有趣的游戏 (AC自动机+概率DP+高斯消元)