(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. git 的安装与初始化

    1搭建本地git服务器: 1.1安装git 对于ubuntu系统,一般自带git,可以使用git --version 查看版本号 ,或使用apt-get install git  . centos上对 ...

  2. 4 扩展库Scipy

    https://www.scipy.org/ 1. numpy    矩阵 2. matplotlib 绘图库 3. pandas 高效的Series和DataFrame数据结构 4.5 ndarry ...

  3. Python之字典方法

    def clear(self): # 清除所有内容 """ D.clear() -> None. Remove all items from D. "&q ...

  4. Python中集合set()的使用及处理

    在Python中集合(set)与字典(dict)比较相似,都具有无序以及元素不能重复的特点 1.创建set 创建set需要一个list或者tuple或者dict作为输入集合 重复的元素在set中会被自 ...

  5. GUI开发:实时显示摄像头图像

    import tkinter as tk from PIL import Image, ImageTk import cv2 import numpy as np import time g_exit ...

  6. Qt的子窗口和父窗口阻塞问题

    在图形界面中,软件设计者通常需要将活跃窗口限制为一个.在某个窗口活跃时,它的父窗口被它挡住或者挡住一部分,这时候用鼠标去点击父窗口是没有作用的.问题的关键在于将子窗口设置模态: void MainWi ...

  7. 第一次靶场练习:SQL注入(1)

    SQL注入1 本文章目的是对相关的黑客内容进一步了解,如有人违反相关的法律法规,本人概不负责 一.学习目的: 利用手工注入网站 利用sqlmab注入 二.附件说明 靶场网址:http://117.41 ...

  8. pytorch 读数据接口 制作数据集 data.dataset

    [吐槽] 啊,代码,你这个大猪蹄子 自己写了cifar10的数据接口,跟官方接口load的数据一样, 沾沾自喜,以为自己会写数据接口了 几天之后,突然想,自己的代码为啥有点慢呢,这数据集不大啊 用了官 ...

  9. JS 删除Array对象中的元素。

    var idTemp=new Array(); var nameTemp = new Array(); nameTemp.splice($.inArray(“1”, nameTemp),1); idT ...

  10. Sublime使用及配置C编译器

    一.环境配置 在安装了MinGW+Gcc的基础上做如下设置—— 新建编译系统c.sublime-build: { "cmd" : ["gcc", "$ ...