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

  • 相关阅读:
    char array 与string
    汗= =
    看来要学 Asp.Net 了
    安装 Xamarin for Visual Studio
    Xamarin for Visual Studio 3.11.658 Alpha 版 破解补丁
    用 Xamarin for VS 创建 aar 文件的绑定
    Android中当前墙纸Wallpaper存放的位置
    Android中动态改变控件的大小的一种方法
    程序员学习能力提升三要素(读书笔记)
    让Android软键盘默认进入英文键盘
  • 原文地址:https://www.cnblogs.com/huangzzz/p/8321805.html
Copyright © 2011-2022 走看看