题目:有2中面条各n碗。每次抛硬币推断吃哪一种(到一种吃完为止)。问抛硬币的数学期望。

分析:动态规划。概率dp。求出每种结束状态(即,有一种吃完)的概率,分别乘以步长即为期望。

大黄解法:状态位剩余的碗数,逆向求解,状态方程:

DP[ i ][ j ] = (DP[ i-1 ][ j ]+DP[ i ][ j-1 ])/2 + 1 { orz~~ (所有20行代码就能搞定) }。

说明:(2011-09-27 03:22)。

#include <stdio.h>
#include <stdlib.h> double p[ 1002 ][ 1002 ];
double q[ 1002 ]; int main()
{
for ( int i = 0 ; i <= 1000 ; ++ i )
for ( int j = 0 ; j <= 1000 ; ++ j )
p[ i ][ j ] = 0.0;
p[ 0 ][ 0 ] = 1.0;
for ( int i = 0 ; i <= 1000 ; ++ i )
for ( int j = 0 ; j <= 1000 ; ++ j ) {
p[ i+1 ][ j ] += p[ i ][ j ]*0.5;
p[ i ][ j+1 ] += p[ i ][ j ]*0.5;
} for ( int i = 1 ; i <= 1000 ; ++ i ) {
double sum = p[ i ][ 0 ]*i;
for ( int j = i-1 ; j >= 1 ; -- j )
sum += (i+j)*(p[ i ][ j ]-p[ i ][ j-1 ]*0.5);
q[ i ] = sum*2.0;
} int t,n;
while ( scanf("%d",&t) != EOF )
while ( t -- ) {
scanf("%d",&n);
printf("%.2lf\n",q[ n ]);
}
return 0;
}

zoj 2949 - Coins of Luck的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  3. ZOJ 1666 G-Square Coins

    https://vjudge.net/contest/67836#problem/G People in Silverland use square coins. Not only they have ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. zoj 3356 Football Gambling II【枚举+精度问题】

    题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...

  6. zoj 3627#模拟#枚举

    Treasure Hunt II Time Limit: 2 Seconds                                     Memory Limit: 65536 KB    ...

  7. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  8. [LeetCode] Arranging Coins 排列硬币

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...

  9. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

随机推荐

  1. linux之tr

    通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复 ...

  2. javaScript防止拦截新窗口打开页面

    原文发布时间为:2009-05-04 -- 来源于本人的百度文章 [由搬家工具导入] 兼容IE.FF.GOOGLE。防止拦截。。。。 <html xmlns="http://www.w ...

  3. 【自己的练习git】自己的git练习

    liqiang@username MINGW64 ~/Desktop$ mkdir TestGit        新建目录 liqiang@username MINGW64 ~/Desktop$ cd ...

  4. linux内核情景分析之匿名管道

    管道的机制由pipe()创建,由pipe()所建立的管道两端都在同一进程.所以必须在fork的配合下,才可以在具有亲缘关系的进程通信 /* * sys_pipe() is the normal C c ...

  5. Centos7 安装docker ce

    一. 安装docker 1.升级rpm包 yum -y update 2. 通过命令设置Docker CE 资源库: yum install -y yum-utils yum-config-manag ...

  6. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. 网站防火墙探测工具Wafw00f

     网站防火墙探测工具Wafw00f 现在网站为了加强自身安全,通常都会安装各类防火墙.这些防火墙往往会拦截各种扫描请求,使得测试人员无法正确判断网站相关信息.Kali Linux提供了一款网站防火墙探 ...

  8. 如何在window上把你的项目提交到github

    1.首先你需要在https://github.com/ 上注册一个账户 2.注册成功以后,你需要新建一个repository(储藏室),这个用来存放你要上传的项目 点击中间的带加号的图标就可以新建re ...

  9. Copy Records From One Data Block To Another Data Block In Oracle Forms

    In this tutorial you will learn to copy the records from one data block to another data block on sam ...

  10. devicemapper: Error running deviceCreate (ActivateDevice) dm_task_run failed

    在一台新机子上面,docker处理完lvs数据卷之后,启动docker服务时,出现了启动失败,失败信息如下: [root@hxin221 ~]# systemctl status docker ● d ...