solution - AT_abc402_e

· · 题解

Solution

显然是爆搜,枚举提交哪个题目,考虑是否 AC 转移即可。不过需要一些优化。

跑了 99ms。当然也可以状压 dp,时间会更优秀一些。

Code

int n,m;
struct prob{int s,c,p;} a[N];
double f[1<<8][5005];

int s,mo;
il double dfs()
{
    if(f[s][mo]!=0.) return f[s][mo];

    double mx=0.; double tmp;
    rep(i,0,n-1) if(!(s>>i&1) && mo-a[i].c>=0)
    {
        mo-=a[i].c;
        s^=(1<<i),tmp=a[i].p*1./100*(dfs()+a[i].s);
        s^=(1<<i),tmp+=(100-a[i].p)*1./100*(dfs());
        chmax(mx,tmp);
        mo+=a[i].c;
    }
    return f[s][mo]=mx;
}

signed main()
{
    read(n,m);
    rep(i,0,n-1) read(a[i].s,a[i].c,a[i].p);

    s=0,mo=m;
    printf("%.20Lf",dfs());

    return 0;
}

华风夏韵,洛水天依!