ACdream 1113 The Arrow (概率DP)
来源:互联网 发布:淘宝店铺公告在哪里改 编辑:程序博客网 时间:2024/05/22 17:31
ACdream 1113 The Arrow (概率DP):http://acm.hust.edu.cn/vjudge/contest/view.action?cid=114332#problem/E 传送门:nefu
题面:
Description
The history shows that We need heroes in every dynasty. For example, Liangshan Heroes. People hope that these heroes can punish the bad guys and recover the justice. Nowadays, we also need heroes to provent us from being chopped, or being attacked by a bomb.
Kuangbin is a very very very very very.... (very * 1e9 ) good boy, after he knows The Arrow, he want to be The Arrow of China. But he is also a little afraid of being killed by the bad guys. So he decides to throw dices to make the decision.
The dice is a cube with 1 2 3 4 5 6 on it's sides. When he throws a dice, every number is of the same probablity to appear. He will write down a number N in the paper at first, and then throw the dice. When the sum of the number he throwed is less than N, he will keep throwing. But if the sum exceeds N, this throwing does not count.
For example, If the sum is 5,and N is 6, if we throw 2, 5 + 2 > 6, then the sum keeps to be 5.
If he can end the throwing in a certain time, he will make the decision to become The Arrow.
Now , kuangbin wonders that what's the expectation of the time of throwing dices.
Input
First line, The number of cases t <= 100
In the next t lines, there will be t numbers.
every number is not bigger than 100000
Output
Sample Input
11
Sample Output
6.00
题目大意:
一边掷骰子一边求点数之和,如果当前点数之和为sum,再掷一次骰子之后得到点数为y,且满足sum+y>n(n为给定值)时,保持sum不变,求所掷骰子的次数的期望。
题目分析:
dp公式为:
dp[i]=dp[i]*y/6+dp[i+1]*y/6+dp[i+2]*y/6+...+dp[i+6]*y/6+1.
代码实现:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;double dp[100010];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 temp=0; for(int j=1;j<=6;j++) { if(i+j>n) tot++; else temp+=dp[i+j]/6.0; } dp[i]=(temp+1)/(6-tot)*6; } printf("%.2lf\n",dp[0]); } return 0;}
- Acdream 1113 The Arrow(概率dp)
- ACdream 1113 The Arrow (概率DP)
- Acdream 1113 The Arrow(概率dp)
- ACdream 113 The Arrow (概率DP)
- ACdream 1113 The Arrow (概率dp求期望)
- ACdream 1113 The Arrow (概率dp求期望)
- Acedream 1113 The Arrow(概率DP)
- ACdream原创群赛(13)のwuyiqi退役专场 F:The Arrow (概率dp)
- ACdream1113 The Arrow(概率dp)
- acdreamoj1117The Arrow 概率dp
- ACdream Kill The Monster(线性dp)
- ACdream 1072 Kill The Monster (dp)
- ACdream oj1113 概率dp求期望
- ACdream 1079 Walking in the Rain (线性dp)
- [ACdream]哗啦啦村的日常游戏(一)抓个球[概率DP][记忆化搜索]
- Expect the Expected(dp+概率)
- acdream 1072 Kill The Monster (dp)
- acdream 1200 Jump! Jump! Jump! 概率dp+高斯消元
- 机房重构——模板方法模式+单例模式+存储过程优化组合查询
- [CodeForces 27E] Number With The Given Amount Of Divisors (数论 + 反素数)
- Linux yum命令使用教程
- Codeforces Round #334 (Div. 2) C. Alternative Thinking(脑洞)
- 又见01背包
- ACdream 1113 The Arrow (概率DP)
- java学习笔记-java只有值传递
- JavaScript构造函数及原型对象 使用Object或对象字面量创建对象 工厂模式创建对象 构造函数模式创建对象 原型模式创建对象 构造与原型混合模式创建对象
- 十一、图的存储---(0)什么是图
- 微信开发 提示 Redirect_uri参数错误解决方法
- 23种设计模式(1):单例模式
- 2016.04.29
- HDOJ(HDU) 2103 Family planning(需要注意范围)
- 开源镜像更新监测