设为首页 加入收藏

TOP

Acdream 1113 The Arrow(概率dp)
2015-11-21 00:58:39 来源: 作者: 【 】 浏览:1
Tags:Acdream 1113 The Arrow 概率

?

题意:

初始状态在0,每次丢骰子[1,6],如果现在在x,丢的骰子数为y,如果x+y>n那么就还停留在x。

求从0到n所丢骰子次数的期望。

分析:

这题和之前的就更改了一点就是如果现在在x,丢的骰子数为y,如果x+y>n那么就还停留在x。

那么我们设dp[i]表示从i到n要丢的骰子次数的期望

那么

我们设每次有x次的可能留在原地

dp[i] =dp[i]*y/6+dp[i+1]/6+dp[i+2]/6..+1;

然后化简一下得到dp[i]的公式。

代码如下:

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; const int maxn = 1e5+10; double dp[maxn]; int main() { int t,n; scanf(%d,&t); while(t--){ scanf(%d,&n); memset(dp,0,sizeof(dp)); for(int i=n-1;i>=0;i--){ int tot=0; double tmp=0; for(int j=1;j<=6;j++){ if(i+j>n) tot++; else tmp+=dp[i+j]/6.0; } //cout<
      
       

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Factorial Trailing Zeroes -- le.. 下一篇Criteria――Hibernate的面向对象..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: