题解 | #抽卡#

抽卡

https://ac.nowcoder.com/acm/problem/210516

(f[st]+1)p[j]=jp[j]f[st(1<<j)](f[st] + 1) * \sum p[j] = \sum_{j} p[j] * f[st|(1<<j)] (f[st]+1)p[j]=jp[j]f[st(1<<j)] 看不懂的话就展开来

#include<bits/stdc++.h>
using namespace std;

const int N = 21;

int n;
double f[1<<N],p[N]; //f[st]表示集齐st状态的卡的期望包数

void solve(){
    f[(1<<n)-1]  = 0;
    for(int i = (1<<n) - 2; i>=0 ;i--)
    {
        int st = i;double p_v = 0;
        for(int j=0;j<n;j++){
            if((st >> j & 1) == 0)
                p_v += p[j] , f[i] += p[j] * f[i | (1<<j)];
        }
        f[i] = (f[i]+1.0)/p_v;
    }
    cout << f[0] << endl;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> p[i];
    //cout << p[0] << endl;
    solve();
    return 0;
}
全部评论

相关推荐

牛客773130651号:巨佬,简历模板换成上下的,左右的很烦,hr看着不爽。。。科大随便乱杀,建议能保研就保研,不行也得考一下 ,985硕去干算法,比开发强多了。开发许多双非都能搞,学历优势用不上,算法有门槛
点赞 评论 收藏
分享
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务