[spoj Favorite Dice ][期望dp]
(1)https://vjudge.net/problem/SPOJ-FAVDICE
题意:有一个n面的骰子,每一面朝上的概率相同,求所有面都朝上过至少一次的总次数期望。
题解:令dp[i]表示 i 面满足条件的期望次数,则有 dp[i]=$\sum_{j=1}^{i-1}$(Pj*(本次操作对最终期望的贡献+dp[i]))+$\sum_{j=1}^{n-(i-1)}$(Qj*(本次操作对最终期望的贡献+dp[i-1])),其中Pj表示出现已经出现过数字的概率,由于是等概率事件,所以这里所有的Pj都是1/n,同理Qj都是1/n,这道题目求的是次数,所以每次操作对最终期望的贡献都是1,所以这道题写下来就是dp[i]=$\sum_{j=1}^{i-1}$((1/n+dp[i])+$\sum_{j=1}^{n-(i-1)}$((1/n)),化简整理可得转移方程dp[i]=dp[i-1]+n/(n-(i-1))
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using namespace std;
//#define io_test
#define debug(x) cout<<x<<"$$$$"<<endl;
typedef long long ll;
double dp[];
int main()
{
#ifdef io_test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // io_test
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
dp[]=;
for(int i=;i<=n;i++){
dp[i]=dp[i-]+1.0*n/(n-(i-));
// debug(dp[i]);
}
printf("%.2lf\n",dp[n]);
}
return ;
}
(2)http://2050.acmclub.cn/contests/contest_showproblem.php?pid=1001&cid=2
题意:有n+m条路,其中n条是正确的路,走每条路消耗的时间为ai,正确的路通往终点,剩下m条为错误的路,走每条路消耗的时间为bi,求到终点用时的期望是否大于y
题解:令dp[i]表示第i次找到正确的路的期望时间,显然dp[0]=0,而最后要求的时间期望就是dp[1],则效仿上题有dp[1]=$\sum_{i=1}^{m}$(Pi*(bi+dp[1]))+$\sum_{i=1}^{n}$(Qi*(ai+dp[0])),由于是等概率事件,所以Pi和Qi都是1/(n+m),所以dp[1]=$\sum_{i=1}^{m}$((1/(n+m))*(bi+dp[1]))+$\sum_{i=1}^{n}$((1/(n+m)*ai)),化简得到dp[1]=($\sum_{i=1}^{n}$ai+$\sum_{i=1}^{m}$bi)/n
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using namespace std;
//#define io_test
#define debug(x) cout<<x<<"$$$$"<<endl;
typedef long long ll;
int a[],b[];
int main()
{
#ifdef io_test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // io_test
int t;
scanf("%d",&t);
while(t--){
int n,m,y;
ll sum1=;
ll sum2=;
scanf("%d%d%d",&n,&m,&y);
for(int i=;i<=n;i++){scanf("%d",&a[i]);sum1+=a[i];}
for(int i=;i<=m;i++){scanf("%d",&b[i]);sum2+=b[i];}
if(sum1+sum2>n*y){
printf("Wait\n");
}
else{
printf("Go\n");
}
}
return ;
}
[spoj Favorite Dice ][期望dp]的更多相关文章
- SPOJ Favorite Dice(概率dp)
题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...
- SP1026 FAVDICE - Favorite Dice[期望DP]
也许更好的阅读体验 \(\mathcal{Description}\) 一个\(n\)面的骰子,求期望掷几次能使得每一面都被掷到 输入有\(T\)组数据,每次输入一个\(n\) 输出保留两位小数 \( ...
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- LightOj:1030-Discovering Gold(期望dp模板)
传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- [NOIP2016]换教室 D1 T3 Floyed+期望DP
[NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...
随机推荐
- day02 : JPA的基本使用和多种缓存技术对比
1). 按照条件查询标签: ① 在controller种添加方法 [确保表中有数据] /** * 根据条件查询 */ @PostMapping("/search") public ...
- centos7搭建日志服务器
服务器端 修改配置文件 /etc/rsyslog.conf中 $ModLoad imudp $UDPServerRun 514 打开日志服务监听 修改/etc/sysconfig/rsyslog文件 ...
- 对弈win32笔记
对弈的win32笔记 一:Windows程序运行原理 一.Windows四大模块程序 1.1控制台程序 没有自己的窗口,dos-显示或者运行程序,入口mian() 1.2窗口程序 有自己的窗口,w ...
- JAVAEE期末项目------文章发布系统
项目文档和代码的GitHub地址:https://github.com/xiangbaobaojojo/- 1.项目介绍 (计科四班 蔡春燕 20150141401)和我 陈香宇(计科四班 201 ...
- CentOS7的网卡重启方法
1.centos6的网卡重启方法:service network restartcentos7的网卡重启方法:systemctl restart network 2.DNS配置文件:cat /etc/ ...
- C# 检查数字
#region 检查数字 public bool IsNumeric(string value) { bool result; try { int x = int.Parse(value); resu ...
- python3+cv2+andiord安卓摄像头
#coding=utf-8import cv2 import time if __name__ == '__main__': cv2.namedWindow("camera",1) ...
- linux 常见技巧
1.# :表示权限用户(如:root) $:表示普通用户 开机提示:login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后, 可以进入相应的用户环境. 退出当前shell,输 ...
- Js/如何修改easyui修饰的input的val值
1.关于js对input值的修改介绍:一般js改变input的val值,我一直使用的方法是: $('#id').val('test');这样的方式来进行修改.但是我使 用了class="ea ...
- NSArray NSMutableArray
NSArray 或者 NSMUtableArray 去除重复的数据: 原来集合操作可以通过valueForKeyPath来实现的,去重可以一行代码实现: [array valueForKeyPath: ...