Discovering Gold (期望,递推)
来源:互联网 发布:无间道2 知乎 编辑:程序博客网 时间:2024/06/14 06:48
You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold.
Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice after throwing, you add X to your position and collect all the gold from the new position. If your new position is outside the cave, then you keep throwing again until you get a suitable result. When you reach the Nth position you stop your journey. Now you are given the information about the cave, you have to find out the expected number of gold you can collect using the given procedure.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a blank line and an integer N (1 ≤ N ≤ 100) denoting the dimension of the cave. The next line contains N space separated integers. The ith integer of this line denotes the amount of gold you will get if you come to the ith cell. You may safely assume that all the given integers will be non-negative and no integer will be greater than 1000.
Output
For each case, print the case number and the expected number of gold you will collect. Errors less than 10-6 will be ignored.
Sample Input
3
1
101
2
10 3
3
3 6 9
Sample Output
Case 1: 101.0000000000
Case 2: 13.000
Case 3: 15
// 期望,递推// 从最后一个出发往前遍历,记录从 i 位到 n 的期望 #include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<queue>#include<algorithm>#define ll long long#define inf 0x3f3f3f3f#define maxn 1000007 // 1e6+7using namespace std;int a[120];double num[120];int main(){ int t,n; scanf("%d",&t); for(int k = 1; k <= t; k ++) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i = n-1; i >= 0; i --) { num[i] = a[i]; int t2 = n - 1 - i; t2 = min(t2,6); // 最大走 6 步 double tmp = 0; for(int j = i+1 ; j <= i + t2 ; j ++) tmp += num[j]; if(t2 != 0) num[i] += 1.0 / t2 * tmp; } printf("Case %d: %lf\n",k,num[0]); } return 0;}
- Discovering Gold (期望,递推)
- Light OJ 1030 - Discovering Gold(期望)
- LightOJ 1030 - Discovering Gold (期望dp)
- 【LightOJ 1030】Discovering Gold(期望DP)
- LightOJ1030- Discovering Gold(期望dp)
- lightoj 1030 Discovering Gold[ 期望 ]
- LightOJ - 1030 Discovering Gold 期望
- lightoj 1030 - Discovering Gold 【期望】
- LightOJ 1030 Discovering Gold(期望)
- 【概率&期望】Discovering Gold LightOJ
- 【期望dp】LightOJ 1030 Discovering Gold
- LightOJ 1030 Discovering Gold(期望DP)
- lightoj1030 - Discovering Gold【概率dp求期望】
- lightOJ Discovering Gold(期望DP入门)
- lightoj 1030 Discovering Gold 概率期望
- LightOJ 1030 Discovering Gold + Hdu4405 Aeroplane chess (期望)
- [水+期望dp] light oj 1030 Discovering Gold
- lightoj 1030 Discovering Gold 概率dp求期望
- 解决使用小米手机调试android开发程序的问题
- 农村,是否值得你留恋?
- 总结jQuery的基础知识
- 方法重写Override笔记及其与Overload(重载)的区别
- 全局时间转换器
- Discovering Gold (期望,递推)
- github百度百科
- 使用Reachability的一个问题
- Grpc系列一 第一个hello world 例子
- 等和的分隔子集
- Angular2发布思路(整理官网Deployment页面)
- BZOJ 1146 [CTSC2008]网络管理Network
- Longest Substring Without Repeating Characters
- KVM虚拟机