ACdream 113 The Arrow (概率DP)
来源:互联网 发布:centos php exec 权限 编辑:程序博客网 时间:2024/05/24 06:50
传送门
The Arrow
Problem 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
Source
Manager
题目大意:
就是你在位置 0 处,你想到 n 位置,每次可以通过掷色子的方式来判断走几步,假设当前位置是 x 你置了是 y 点,那么如果 x+y > n 的话, 我们就待在原地不动,否则我们就走 y 步。让我们求得就是从 0 点走到 n 点掷色子的次数的期望
解题思路:
很明显这是一道概率的题,那么我们采用什么方式来做呢,应该是DP了,定义 DP [ i ] 表示的是:从 i 点 到 n 点的置的色子的期望,那么DP [ i ] 等于什么呢,要是我们把 这个状态转移方程写出来就行了。DP[ i ] = DP[ i+1 ]/6.0 + DP[ i+2 ] / 6.0 +... DP[ i+6 ] /6.0 + 1 + DP[ i ]*x/6(x 表示假设 有 x 次i+j > n的次数)如果写程序的话,我们只需要两层循环,外层循环就是 从 n-1 循环到 0 ,内层循环就是 从 1 循环到 6 ,if( i+j > n) 的话用一个数记录一下,最后就是 求 DP[n],还得移项,求一下 DP[ n ]就行了。
My Code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 1e5+5;double dp[MAXN];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); memset(dp, 0, sizeof(dp)); for(int i=n-1; i>=0; i--)///注意从n-1开始 { int cnt = 0;///i+j>n的次数也就是 原地不动的次数 double sum = 0; for(int j=1; j<=6; j++) { if(i+j > n) cnt++; else dp[i] += dp[i+j]/6; } dp[i] = (dp[i]+1)/(6-cnt)*6;///移项求的 } printf("%.2lf\n",dp[0]); } return 0;}
- ACdream 113 The Arrow (概率DP)
- Acdream 1113 The Arrow(概率dp)
- ACdream 1113 The Arrow (概率DP)
- Acdream 1113 The Arrow(概率dp)
- ACdream 1113 The Arrow (概率dp求期望)
- ACdream 1113 The Arrow (概率dp求期望)
- ACdream原创群赛(13)のwuyiqi退役专场 F:The Arrow (概率dp)
- Acedream 1113 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+高斯消元
- 【BZOJ2324】营救皮卡丘,费用流
- RxJava学习(四)
- HDU2604 Queuing(矩阵快速幂)
- [java] 多态实现的JVM调用过程
- java 时区问题 SimpleDateFormat 时区大全
- ACdream 113 The Arrow (概率DP)
- Umeng 推送
- 根据屏幕上一条线求出线两侧形成的路的Path
- STL中的一些操作
- 根据二叉树的前序遍历和中序遍历构建二叉树的c语言完整代码
- HDU 5253 连接的管道(最小生成树-Kruskal+并查集)
- Nopcommerce 3.7 增加了Redis 作为缓存啦
- 分布式系统总结
- mysql表垂直分割和水平分割