zoukankan      html  css  js  c++  java
  • 概率dp

    题目:http://codeforces.com/gym/101606

    Problem F Flipping Coins
    Here’s a jolly and simple game: line up a row of N identical coins, all with the heads facing down onto the table and the tails upwards, and for exactly K times take one of the coins, toss it into the air, and replace it as it lands either heads-up or heads-down. You may keep all of the coins that are face-up by the end. Being, as we established last year, a ruthless capitalist, you have resolved to play optimally to win as many coins as you can. Across all possible combinations of strategies and results, what is the maximum expected (mean average) amount you can win by playing optimally?
    Input • One line containing two space-separated integers: – N (1 ≤ N ≤ 400), the number of coins at your mercy; – K (1 ≤ K ≤ 400), the number of flips you must perform.
    Output
    Output the expected number of heads you could have at the end, as a real number. The output must be accurate to an absolute or relative error of at most 10−6.
    Sample Input 1 Sample Output 1 2 1 0.5
    Sample Input 2 Sample Output 2 2 2 1
    Sample Input 3 Sample Output 3 2 3 1.25
    Sample Input 4 Sample Output 4 6 10 4.63476563
    Sample Input 5 Sample Output 5 6 300 5.5

    题意:

    输入n个硬币和投n次求最多硬币正面朝上的期望

    ps;当所有面朝上时还会继续投

    思路:dp(表示只会这一种dp)

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<set>
    #include<algorithm>
    #include<map>
    #define maxn 200005
    using namespace std;
    int main()
    {
        int n,b;
        cin>>n>>b;
        double dp[405][405];
        dp[0][0]=1;
        for(int i=1;i<=b;i++)
            for(int j=0;j<=i;j++){
        if(j<n)
        {
    
            dp[i][j]+=dp[i-1][j]/2;
            dp[i][j+1]+=dp[i-1][j]/2;
        }
        else if(j==n)
        {
            dp[i][j-1]+=dp[i-1][j]/2;
            dp[i][j]+=dp[i-1][j]/2;
        }
      }
      double ans=0;
         for(int i=0;i<=n;i++)
                ans+=dp[b][i]*i;
            printf("%.8lf
    ",ans);
      return 0;
    }

    这里分享n种概率dp

    http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710606.html

  • 相关阅读:
    PHP实反向代理-收藏
    微信小程序实例-获取当前的地理位置、速度
    Entity Framework Core 实现读写分离
    将ASP.NET Core应用程序部署至生产环境中(CentOS7)(转)
    Centos 7防火墙firewalld开放80端口
    Asp.net Core 使用Redis存储Session
    .net core 使用Autofac依赖注入
    .net core 1.0 实现负载多服务器单点登录
    用ASP.NET Core 1.0中实现邮件发送功能-阿里云邮件推送篇
    阿里大鱼.net core 发送短信
  • 原文地址:https://www.cnblogs.com/huangzzz/p/8321805.html
Copyright © 2011-2022 走看看