• [min-max容斥][dfs] Hdu P4336 Card Collector


    Problem Description

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.
    As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.

    题解

    • 设ti为第一次获得第i种卡片的期望时间,那么要求的就是E(max(ti))
    • 根据min-max反演可以得到E(max(s))=∑t∈s(-1)^(|T|-1)E(min(T))
    • 然后可以知道,E(min(T))=1/∑pi
    • 最后暴力出奇迹

    代码

     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 int n;
     5 double ans,p[30];
     6 void dfs(int d,double sum,double op)
     7 {
     8     if (d>n) { if (sum>1e-9) ans+=op/sum; return; }
     9     dfs(d+1,sum+p[d],-op),dfs(d+1,sum,op);
    10 }
    11 int main()
    12 {
    13     while (scanf("%d",&n)!=EOF)
    14     {
    15         for (int i=1;i<=n;i++) scanf("%lf",&p[i]);
    16         ans=0,dfs(1,0,-1),printf("%.4lf
    ",ans);
    17     }
    18 }
  • 相关阅读:
    sql server 常用脚本之table操作
    sql server 常用脚本之数据库操作
    PHP 生成日历
    转 mysql 问题一则
    转 php 前端知识点
    转 nbu 知识点
    转 php python 知识点
    oralce 问题几则 ORA-19504 报错
    AWR 报告脚本实现
    转 php 框架 Php 依赖框架 后台 调用python 脚本
  • 原文地址:https://www.cnblogs.com/Comfortable/p/11335364.html
Copyright © 2020-2023  润新知