(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. vue中几种常见技巧

    1.校验延迟:点击进入页面不希望校验必填字段this.$nextTick(() => { this.$refs.formRules.clearValidate() })2.$on $emit $ ...

  2. Linux 动态链接库 - dll劫持

    如何使用动态链接库 Linux下打开使用动态链接库需要三步(实际上和windows下基本一样):1.加载动态链接库,通过调用库函数dlopen()获得链接库的句柄,对应于windows下的 AfxLo ...

  3. mybatis源码解析之Configuration加载(三)

    概述 上一篇我们主要分析了下<environments>标签下面,transactionManager的配置,上问最后还有个遗留问题:就是在设置事物管理器的时候有个autocommit的变 ...

  4. 如何下载最新Xshell版本、免费官方正版软件的技巧过程

    我们在操作和管理Linux VPS.服务器的时候,肯定需要使用SSH工具,对于这个工具网上有很多免费和付费版本.对于我们用户来说肯定会较多的选择免费软件.其中使用较多的还是Xshell工具,也是我认为 ...

  5. java后台常用json解析工具问题小结

    若排版紊乱可查看我的个人博客原文地址 java后台常用json解析工具问题小结 这里不细究造成这些问题的底层原因,只是单纯的描述我碰到的问题及对应的解决方法 jackson将java对象转json字符 ...

  6. 使用turtle画故宫(伍奇,侯俊豪小组)

    这个代码主要有两个部分,第一部分是画出故宫,第二部分是用random函数随机画心,故宫部分设置多个函数和循环再进行颜色填充即可完成. 此处为视频链接 from turtle import* impor ...

  7. easyui datagrid 后台返回所有数据,前台分页

    function pagerFilter(data) { if (typeof data.length == 'number' && typeof data.splice == 'fu ...

  8. Windows10 安装QT问题

    在网上download qt-opensource-windows-x86-winrt-msvc2013-5.8.0.exe 版本安装完成后,New “Qt Widgets application” ...

  9. spring Ioc容器之使用XML配置Bean

    1.项目截图 2.创建xml文件 3.打印机接口 package com.example.demo.computerTest; public interface Printer { void init ...

  10. 通过sqlalchemy操作mysql

    # 安装 pip3 install sqlalchemy import sqlalchemy from sqlalchemy import create_enginefrom sqlalchemy.e ...