(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]的更多相关文章

  1. SPOJ Favorite Dice(概率dp)

    题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...

  2. SP1026 FAVDICE - Favorite Dice[期望DP]

    也许更好的阅读体验 \(\mathcal{Description}\) 一个\(n\)面的骰子,求期望掷几次能使得每一面都被掷到 输入有\(T\)组数据,每次输入一个\(n\) 输出保留两位小数 \( ...

  3. LightOJ 1248 Dice (III) (期望DP / 几何分布)

    题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...

  4. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  5. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  6. LightOj:1030-Discovering Gold(期望dp模板)

    传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...

  7. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  8. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  9. [NOIP2016]换教室 D1 T3 Floyed+期望DP

    [NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...

随机推荐

  1. 解决Python图片处理模块pillow使用中出现的问题

    最近爬一个电影票房的网站(url:http://58921.com/alltime),上面总票房里面其实是一张图片,那么我需要把图片识别成文字,来获取票房数据.   我头脑里第一想到的解决方案就是要用 ...

  2. python threading模块中的join()方法和setDeamon()方法的一些理解

    之前用多线程的时候看见了很多文章,比较常用的大概就是join()和setDeamon()了. 先说一下自己对join()的理解吧: def join(self, timeout=None): &quo ...

  3. Windows Server 2008 R2 服务器系统安装及配置全过程图文详解

    前言 本文主要介绍了 windows Server 2008 R2 服务器系统的安装及相关配置. 介绍的是以优盘的方式安装. 写这篇博文的目的一来是为了供有需要的网友参考, 二来自己也在此做个记载. ...

  4. PYTHON实现算术表达式构造二叉树

    LEETCOCE 224. Basic Calculator Implement a basic calculator to evaluate a simple expression string. ...

  5. URL 通过Get方式传递数组参数

    URL 通过Get方式传递数组参数 方法1: ?id=1&id=2&id=3 后台获取时,只需要reqeust.getParameterValues("id") 获 ...

  6. 阶段02JavaWeb基础day04mysql

    数据库--MySql 数据仓库.就与我们之前学过的纯文本,properties这些技术一样.用来保存数据.并提供对数据进行增删改查的操作.我们以后做项目时,项目中的数据都是保存在数据库中的.//--- ...

  7. 查询总耗CPU最多与平均耗CPU最多的SQL语句

    总耗CPU最多的前20个SQL total_worker_time AS [总消耗CPU 时间(ms)],execution_count [运行次数], qs.total_worker_time AS ...

  8. Problem 7: 10001st prime

    By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. ...

  9. redis总结(一)的持久化的取舍和选择以及作用

    1.redis持久化 在客户端发布save的过程中有可能造成阻塞,如一千万条数据同时保存并生成二进制RDB文件的时候,此时就会延迟堵塞. 文件策略是如果存在老的RDB文件,会用新的文件替代老的文件如下 ...

  10. 【译】REM vs EM - 世纪之争

    原文链接:https://zellwk.com/blog/rem-vs-em/ 在网络上排版的最佳做法之一是使用像rem和em这样的相对单位. 问题是,你应该使用哪个? 在rem支持者和em支持者之间 ...