zoj 2949 - Coins of Luck
题目:有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的更多相关文章
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- ZOJ 1666 G-Square Coins
https://vjudge.net/contest/67836#problem/G People in Silverland use square coins. Not only they have ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- zoj 3356 Football Gambling II【枚举+精度问题】
题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...
- zoj 3627#模拟#枚举
Treasure Hunt II Time Limit: 2 Seconds Memory Limit: 65536 KB ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- [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 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- session失效时间
1.web容器中设置(此处以tomcat为例) <session-config> <session-timeout>30</session-timeout> < ...
- 洛谷P1908 逆序对
P1908 逆序对 2.2K通过 4.4K提交 题目提供者该用户不存在 标签云端 难度普及/提高- 时空限制1s / 128MB 提交 讨论 题解 最新讨论更多讨论 归并排序党注意了!数组要开… ...
- jmeter的参数化方法汇总
一.User Defined Variable 1.添加的位置 Add->Config Element->User Defined Variable 2.使用 变量phone添加成功后,在 ...
- 使用docker-maven-plugin插件构建docker镜像(已过时)
可以参考博客:https://blog.csdn.net/aixiaoyang168/article/details/77453974 docker-maven-plugin官网推荐在新项目中使用do ...
- HDOJ 1171 Big Event in HDU
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- *LOJ#2085. 「NOI2016」循环之美
$n \leq 1e9,m \leq 1e9,k \leq 2000$,求$k$进制下$\frac{x}{y}$有多少种不同的纯循环数取值,$1 \leq x \leq n,1 \leq y \leq ...
- 在VS2013中使用boost库遇到的问题及解决(转)
原文转自 https://my.oschina.net/SunLightJuly/blog/676891?p=1 最近的项目需要集成一个使用了boost库的开源库.原本应该是比较简单的工作,因为使用的 ...
- Spring积累总结
1.spring 的优点: 1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它很 ...
- dracut 基本介绍
dracut 维基 https://dracut.wiki.kernel.org/index.php/Main_Page http://www.360doc.com/content/13/042 ...
- my.ini配置详解
Mysql my.ini 配置文件详解 #BEGIN CONFIG INFO #DESCR: 4GB RAM, 只使用InnoDB, ACID, 少量的连接, 队列负载大 #TYPE: SYSTEM ...