Codeforces 30C shooting gallery simple DP

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.