题目:有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. python知识集合

    1.list list是一种有序的集合 例子:classmates = ['Michael', 'Bob', 'Tracy']; 方法:1. len len(classmates) //3 2.app ...

  2. npm使用问题总结

    1.报错npm run dev error [npm ERR! code ELIFECYCLE] 解决方法 rm -rf node_modules rm package-lock.json npm c ...

  3. AngularJS实现TodoMVC

    一个小的to do list,界面如下 首先安装angular js,出现了无非安装到桌面的问题,安装到D盘了 npm install angular 文件结构: index.html: <!d ...

  4. mybatis 从数据库查询的信息不完整解决办法

    List<Product> products = productService.getProductListWithPage(productQuery); 今天碰到一个很奇怪的现象,上面的 ...

  5. 【CF1068C】Colored Rooks(构造)

    题意: 思路: #include<cstdio> #include<cstring> #include<string> #include<cmath> ...

  6. powershell常用

    对于powershell,比较强大的shell,可以直接调用.net进行下载等等 get-command|where-object{$_.name -like 'write*'} get-wmiobj ...

  7. 转一个网址,canvas用法

    http://blog.csdn.net/jia20003/article/details/9251893 http://www.w3school.com.cn/cssref/pr_animation ...

  8. Day 32 process&threading_4

    线程和进程 4 一.multiprocessing模块 multiprocessing包是Python中的多进程管理包. 与threading.Thread类似,它可以利用multiprocessin ...

  9. Block为什么使用Copy?

    block:本质就是一个object-c对象block:存储位置,可能分为3个地方:代码去,堆区.栈区(ARC情况下会自动拷贝到堆区,因此ARC下只能有两个地方:代码去.堆区)代码区:不访问栈区的变量 ...

  10. react 使用antd的在图片列表或表格中实现点击其他元素Checkbox选中功能

    antd官网上的Checkbox功能只能单独使用,在表格中加入Checkbox也只能点击Checkbox按钮才能实现选中或取消功能 如果我们要实在表格行中点击或在图片列表中点击图片就能实现选中或取消, ...