• 概率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

  • 相关阅读:
    软件工程概论第十六周学习进度表
    构建之法阅读笔记06
    软件工程概论第十五周学习进度表
    手机百度输入法的用户体验
    构建之法阅读笔记05
    软件工程概论第十四周学习进度表
    2020/2/1-Python学习计划
    Map Reduce数据清洗及Hive数据库操作
    《大数据技术原理与应用》暑假学习计划_06
    分布式数据库的安装与配置
  • 原文地址:https://www.cnblogs.com/huangzzz/p/8321805.html
Copyright © 2020-2023  润新知