Question link: Click the open link
N balloons
The following n rows x y t Val indicate the time when the coordinates (x, y) of the balloon appear t, the value of the balloon Val
The distance of the gun moving in 1 unit per second
Q:
The maximum value of shooting, starting with a gun aiming at any position.
Ideas:
DP ..
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <math.h>#include <set>#include <vector>#include <map>using namespace std;#define ll long long#define N 2005ll n;struct node{ll x,y,t;double val;}a[N];bool cmp(node aa, node bb){return aa.t<bb.t;}ll dist(node aa, node bb){return (aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y);}ll dis[N][N];double dp[N];int main(){ll i,j,u,v;while(cin>>n){for(i = 1; i <= n; i++)cin>>a[i].x>>a[i].y>>a[i].t>>a[i].val;sort(a + 1, a + 1 + n, cmp);for(i = 1; i <= n; i++) {for(j = i+1; j <= n; j++)dis[i][j] = dis[j][i] = dist(a[i],a[j]);}for(i = 1; i <= n; i++) {dp[i] = a[i].val;for(j = 1; j < i; j++) {if(dis[i][j] > ((a[i].t-a[j].t)*(a[i].t-a[j].t)))continue;dp[i] = max(dp[i], dp[j]+a[i].val);}}double ans = 0;for(i = 1; i <= n; i++)ans = max(ans, dp[i]);printf("%.10lf\n",ans);}return 0;}