codeforces 30C Shooting Gallery (概率dp)

来源:互联网 发布:功德人生软件下载 编辑:程序博客网 时间:2024/05/29 08:43

题意:

给出n个会定时出现的靶子,每个靶子给出出现的时间坐标和能打中概率,问打中靶子数的期望最大值。

题解:

简单的概率dp,dp[i]表示以i为结尾打中靶子数期望的最大值。注意精度!

#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespace std;typedef long long lld;const int oo=0x3f3f3f3f;const lld OO=1LL<<61;const int MOD=1000000007;#define eps 1e-6#define maxn 1005double dp[maxn];struct NODE{    double x,y,t,p;}a[maxn];bool cmp(NODE n1,NODE n2){    return n1.t<n2.t-eps;}double dis(NODE n1,NODE n2){    return sqrt(1.0*(n1.x-n2.x)*(n1.x-n2.x)+1.0*(n1.y-n2.y)*(n1.y-n2.y));}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)            scanf("%lf %lf %lf %lf",&a[i].x,&a[i].y,&a[i].t,&a[i].p);        sort(a+1,a+1+n,cmp);        memset(dp,0,sizeof dp);        dp[0]=0.0;        double ans=0.0;        for(int i=1;i<=n;i++)        {            for(int j=0;j<i;j++)            if(a[i].t-a[j].t>dis(a[j],a[i])-eps||j==0)            {                dp[i]=max(dp[i],dp[j]+a[i].p);            }            ans=max(ans,dp[i]);        }        printf("%.10lf\n",ans);    }    return 0;}/**10 0 0 0.520 0 0 0.65 0 5 0.7*/




0 0
原创粉丝点击