51nod1450 闯关游戏

按照 yi 从大到小的顺序依次决策每个游戏,每个游戏有两种决策,要不然必须到 2 星,要不然过了就行。这个决策过程可以dp。

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=4010;
const double oo=1e16;
struct game
{
    double x,y,z;
    bool operator < (const game &g) const
    {
        return y<g.y;
    }
}a[maxn];
double dp[maxn][maxn];
int n,m;
int main()
{
    //freopen("c.in","r",stdin);
    scanf("%d%d",&n,&m);
    m-=n;
    for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
    sort(a+1,a+n+1);
    for (int i=0;i<m;i++) dp[n][i]=oo;
    for (int i=n-1;i>=0;i--)
    {
        for (int j=0;j<m;j++)
            dp[i][j]=min(
            1000/(a[i+1].x+a[i+1].y)+a[i+1].x/(a[i+1].x+a[i+1].y)*dp[i+1][j]+a[i+1].y/(a[i+1].x+a[i+1].y)*dp[i+1][j+1],
            1000/a[i+1].y+dp[i+1][j+1]);
        dp[i][m]=1000/(a[i+1].x+a[i+1].y)+dp[i+1][m];
    }
    printf("%.8f\n",dp[0][0]);
}

猜你喜欢

转载自blog.csdn.net/sdfzyhx/article/details/74787772