Discovering Gold lightoj 1030
一排1到n的格子,每个格子上有黄金 ai ,你最开始在 1 号,每一次投骰子决定到哪一个格子,超出1~n范围则重新投掷,你到了哪个格子就得到哪个格子的金币,问最终在n 能得到金币的期望。
思路:做题经验,期望都是从后推到前,我们从最大开始dp,
1~6 种情况的传递,但是当前面的格子数少于6的时候需要特判;
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
using namespace std;
const int maxn=1e3+;
int a[maxn];
double dp[maxn];
int main()
{
int T;
int cnt=;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
for(int i=n;i>=;i--){
//对格子数特判的处理
double base=n-i;
if(base>=) base=; dp[i]=a[i];
for(int j=;j<=base;j++){
dp[i]+=dp[i+j]/base;
}
}
printf("Case %d: %f\n",++cnt,dp[]);
}
return ;
}
Discovering Gold lightoj 1030的更多相关文章
- Discovering Gold LightOJ - 1030 (概率dp)
You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c ...
- Discovering Gold LightOJ - 1030 || 概率与期望求法区别
#include<cstdio>//wrong_codes #include<algorithm> using namespace std; ],anss; ],T,TT,n, ...
- LightOJ - 1030 Discovering Gold —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold PDF (English) Statistics For ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- 1030 - Discovering Gold
1030 - Discovering Gold PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 M ...
- [LOJ 1030] Discovering Gold
B - Discovering Gold Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ 1030 Discovering Gold(期望)
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
- LightOj 1030 - Discovering Gold(dp+数学期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...
- LightOJ 1030 - Discovering Gold - [概率DP]
题目链接:https://cn.vjudge.net/problem/LightOJ-1030 You are in a cave, a long cave! The cave can be repr ...
随机推荐
- Java并发,synchronized锁住的内容
synchronized用在方法上锁住的是什么? 锁住的是当前对象的当前方法,会使得其他线程访问该对象的synchronized方法或者代码块阻塞,但并不会阻塞非synchronized方法. 脏读 ...
- ZDialog关闭父窗口、往父窗口传值、刷新父窗口
关闭自己 //关闭自己 top.Dialog.close(); 关闭父窗口 //关闭父窗口 parentDialog.parentWindow.close() 往父窗口传值 //在本页面,调用父页面方 ...
- 在SQL中怎么把一列字符串拆分为多列
--首先,你是按什么规则拆? 我举个例子 你要按字段中的逗号拆开,假设字段名叫text --用charindex和substring这2个函数 select substring(text,1,c ...
- H3C ARP配置
一.ARP简介 ARP(Address Resolution Protocol,地址解析协议)是将IP地址解析为以太网MAC地址(或称物理地址)的协议. 在网络中,当主机或其它网络设备有数据要发送给另 ...
- BK: Data mining: concepts and techniques (1)
Chapter 1 data mining is knowledge discovery from data; The knowledge discovery process is an iterat ...
- TCL 包
包用于创建代码的可重用单元. 程序包提供特定功能的文件集合. 1.创建代码 2.创建包index 打开tclsh,切换到HelloWorld目录,并使用pkg_mkindex 命令创建索引文件. %c ...
- model_Flask
虚拟环境 新建一个虚拟环境:mkvirtualenv 环境名 删除一个虚拟环境:rmvirtualenv 环境名 退出:deactivate win10下安装 1. 打开cmd 安装虚拟环境包 pip ...
- mybatis-plus - MybatisPlusAutoConfiguration
mybatis 的通用maper, 其实有很多, mybatis-plus 算是其中做的比较好的一款了. 这里就来看一下 mybatis-plus 是怎么实现这个通用mapper功能的. 一. Bas ...
- python中可变类型和不可变类型数据的复制
常见的复制方式有以下5种第1种:通过等号[=]复制 - 不论可变还是不可变数据类型,通过[=]复制后都指向同一个内存地址: - 改变复制后的数据(例子中的anotherStr,anotherList) ...
- ASP.NET 模型验证2--验证部分属性
在开发MVC时,模型验证非常常见,平常我们用的应该都是全验证 if(ModelState.IsValid){ //验证成功要做的事 .....} 但是有时候我们需要部分验证,比如修改用户信息时,因为更 ...