题目:有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. token防止重复提交

    Token,可以翻译成标记!最大的特点就是随机性,不可预测,一般黑客或软件无法猜测出来. Token一般用在两个地方: 1: 防止表单重复提交 2: anti csrf攻击(Cross-site re ...

  2. 关于UITextView的限制字数显示,以及emjor表情占用字节处理,复制粘贴字节处理~优化

    //限制字数 #define MAX_LIMIT_NUMS 30 1 #pragma mark -- textview的代理事件 - (BOOL)textView:(UITextView *)text ...

  3. 支付宝APP支付IOS手机端java后台版

    版权声明:http://blog.csdn.net/u012131769/article/details/76639527#t8 转载:http://blog.csdn.net/u012131769/ ...

  4. DB迁移:从SQL Server 2005到MySQL

    一.工具选择 依工作需要进行老产品升级,其中一项重要工作就是将SQL Server数据库改为MySQL数据库,故而在对<各种主流 SQLServer 迁移到 MySQL 工具对比>文章学习 ...

  5. css3 实现多行文本折行

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. linux下創建啓動圖標

    Linux下如何为刚安装好的Eclipse在桌面建一个启动图标?(QtCreator 也可以类似去做). 首先:gedit    /usr/share/applications/eclipse.des ...

  7. python3列表推导式和生成器。

    1.把一个字符串变成 Unicode 码位的列表 >>> symbols = '$¢£¥€¤' >>> codes = [] >>> for sy ...

  8. 关于main函数的参数

    #include <stdio.h> int main(int argc, char const *argv[]) { int i; for ( i = 0; i < argc; i ...

  9. 转载——分享一个html+js+ashx+easyui+ado.net权限管理系统

    EasyUI.权限管理 这是个都快被搞烂了的组合,但是easyui的确好用,权限管理在项目中的确实用.一直以来博客园里也不少朋友分享过,但是感觉好的要不没源码,要不就是过度设计写的太复杂看不懂,也懒得 ...

  10. AC日记——封锁阳光大学 洛谷 P1330

    封锁阳光大学 思路: bfs染色: 如果当前点能通往已染色的点则不能完成: 图不一定联通: 来,上代码: #include <queue> #include <cstdio> ...