ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】
题目链接:https://www.jisuanke.com/contest/2870?view=challenges
题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m次后,硬币向上的期望值。
思路:
1.期望跟概率还是有点不同的,期望要枚举出抛的所有的情况,然后求sigma(i * dp[][])
2.dp[i][j]表示进行i次操作后,有j枚硬币向上的概率。这样就可以求最后的硬币向上的期望了。
3.值得注意的是,预处理的组合数要开 double 型。
代码:
#include<stdio.h>
#include<string.h>
#define mem(a, b) memset(a, b, sizeof(a)) double C[][];//组合数
double P[]; //翻i个硬币的概率,因为正反都是 1 / 2,所以用一维数组表示
double dp[][]; //表示操作i次,有j枚硬币正面向上的概率
int n, m, k; int main()
{
//预处理组合数
C[][] = ;
for(int i = ; i <= ; i ++)
{
C[i][] = ;
for(int j = ; j <= i; j ++)
{
C[i][j] = C[i - ][j - ] + C[i - ][j];
}
}
//预处理i个硬币的概率
P[] = 1.0;
for(int i = ; i <= ; i ++)
P[i] = 0.5 * P[i - ];
int T;
scanf("%d", &T);
while(T --)
{
mem(dp, );
dp[][] = 1.0;
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i < m; i ++)//枚举操作次数
{
for(int j = ; j <= n; j ++)//枚举硬币正面向上的个数
{
if(dp[i][j] == )
continue;
for(int q = ; q <= k; q ++)//枚举抛k枚硬币有多少枚硬币会朝上,枚举所有情况,才是求期望
{
if((n - j) >= k)
dp[i + ][j + q] += dp[i][j] * C[k][q] * P[k];
else
dp[i + ][j + q - (k - (n - j))] += dp[i][j] * C[k][q] * P[k];
}
}
}
double ans = 0.0;
for(int i = ; i <= n; i ++)
{
ans += dp[m][i] * i;
}
printf("%.3lf\n", ans);
}
return ;
}
ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】的更多相关文章
- ACM-ICPC 2017 Asia Urumqi A. Coins
Alice and Bob are playing a simple game. They line up a row of n identical coins, all with the heads ...
- 2017 ICPC Asia Urumqi A.coins (概率DP + 期望)
题目链接:Coins Description Alice and Bob are playing a simple game. They line up a row of nn identical c ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP) 组合数学
Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the head ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- ACM-ICPC 2017 Asia Urumqi G. The Mountain
All as we know, a mountain is a large landform that stretches above the surrounding land in a limite ...
- BZOJ4872 [六省联考2017]分手是祝愿 【期望dp】
题目 Zeit und Raum trennen dich und mich. 时空将你我分开.B 君在玩一个游戏,这个游戏由 n 个灯和 n 个开关组成,给定这 n 个灯的初始状态,下标为 从 1 ...
- 洛谷P3750 [六省联考2017]分手是祝愿(期望dp)
传送门 嗯……概率期望这东西太神了…… 先考虑一下最佳方案,肯定是从大到小亮的就灭(这个仔细想一想应该就能发现) 那么直接一遍枚举就能$O(nlogn)$把这个东西给搞出来 然后考虑期望dp,设$f[ ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)
挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...
随机推荐
- RestTemplate发送GET请求
import org.springframework.web.client.RestTemplate; @Component @Slf4j public class JsSdkUtil { /** * ...
- laravel Passport - Dingo/Api v2.0+Passport 实现 api 认证
第一部分: 安装passport 使⽤ Composer 依赖包管理器安装 Passport : composer require laravel/passport 接下来,将 Passport 的服 ...
- (五)CWnd 所有窗口类的父类,CFrameWnd,Afx_xxx 全局函数,命名规范
CWnd::MessageBox: 只有CWnd的派生类才可以使用MessageBox 所以应用程序类中使用:AfxMessageBox // 初始化 OLE 库 if (!AfxOleInit()) ...
- jQuery系列(十):事件对象
1.事件对象 Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态. (1)什么时候会产生Event 对象呢? 例如: 当用户单击某个元素的时候,我们给 ...
- centos与debian网卡
debian /etc/network/interfaces # This file describes the network interfaces available on your sys ...
- Linux下出现Permission denied解决
今天不想写前言,直接写解决办法 输入命令设置root密码 sudo passwd 得到的答复是 We trust you have received the usual lecture from th ...
- ES节点分析
ES集群概念 集群 一个集群cluster由一个或者多个节点组成,具有相同的cluster.name,协同工作,分项数据和负载. 当有新的节点加入或者删除了一个节点时,集群回感知到并能够平衡数据. E ...
- Docker Image
Docker 对 container 的使用基本是建立在 LXC 基础之上,然而 LXC 存在的问题是难以移动,难以通过标准化的模板去制作.重建.复制和移动 container. 在以 VM 为基础的 ...
- 1.分布式配置中心 spring-cloud-config
pring Cloud 版本:2.1.0.RELEASE 一.server端 1.maven依赖 <dependency> <groupId>org.springframewo ...
- 【SR汇总】效果对比
算法时间效率 -见 https://www.cnblogs.com/wxl845235800/p/10826957.html 1.SRCNN <Learning a Deep Convoluti ...