题目:

Description

Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one bug in the program and adds information about it and its category into a spreadsheet. When he finds bugs in all bug categories, he calls the program disgusting, publishes this spreadsheet on his home page, and forgets completely about the program. 
Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category. 
Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version. 
A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem. 
Find an average time (in days of Ivan's work) required to name the program disgusting.

Input

Input file contains two integer numbers, n and s (0 < n, s <= 1 000).

Output

Output the expectation of the Ivan's working days needed to call the program disgusting, accurate to 4 digits after the decimal point.

Sample Input

1 2

Sample Output

3.0000

题解:

  期望dp入门题,详见http://blog.csdn.net/xingyeyongheng/article/details/25179481

  主要是那个倒推的思想在期望dp中用得很多

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<ctime>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,s;
double f[N][N];
int main(){
//freopen("a.in","r",stdin);
while(scanf("%d%d",&n,&s)!=EOF){
memset(f,,sizeof(f));
for(int i=n;i>=;i--)
for(int j=s;j>=;j--){
if(i==n&&j==s) continue;
double p1=(n-i)*(s-j)*1.0/(n*s)*1.0;
double p2=i*(s-j)*1.0/(n*s)*1.0;
double p3=(n-i)*j*1.0/(n*s)*1.0;
double p4=i*j*1.0/(n*s)*1.0;
f[i][j]=(f[i+][j+]*p1+f[i][j+]*p2+f[i+][j]*p3+)/(-p4);
}
printf("%0.4f",f[][]);
}
return ;
}

刷题总结——Collecting Bugs(poj2096)的更多相关文章

  1. Collecting Bugs poj2096 概率DP

                                                                Collecting Bugs Time Limit: 10000MS   Me ...

  2. 【POJ2096】Collecting Bugs 期望

    [POJ2096]Collecting Bugs Description Ivan is fond of collecting. Unlike other people who collect pos ...

  3. poj2096 Collecting Bugs(概率dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1792   Accepted: 832 C ...

  4. [Poj2096]Collecting Bugs(入门期望dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6237   Accepted: 3065 ...

  5. poj2096 Collecting Bugs[期望dp]

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 5394   Accepted: 2670 ...

  6. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

  7. 刷题记录:[SUCTF 2019]Pythonginx

    目录 刷题记录:[SUCTF 2019]Pythonginx 一.涉及知识点 1. CVE-2019-9636:urlsplit不处理NFKC标准化 2.Nginx重要文件位置 二.解题方法 刷题记录 ...

  8. 刷题记录:[De1CTF 2019]SSRF Me

    目录 刷题记录:[De1CTF 2019]SSRF Me 一.涉及知识点 1.MD5长度扩展攻击 2.Python 2.x - 2.7.16 urllib.fopen支持local_file导致LFI ...

  9. $2019$ 暑期刷题记录1:(算法竞赛DP练习)

    $ 2019 $ 暑期刷题记录: $ POJ~1952~~BUY~LOW, BUY~LOWER: $ (复杂度优化) 题目大意:统计可重序列中最长上升子序列的方案数. 题目很直接的说明了所求为 $ L ...

随机推荐

  1. C#获取Honeywell voyager 1400g扫码后的数据

    一.在类方法中加入 System.IO.Ports.SerialPort com;二.在构造方法中加入 try {   com = new System.IO.Ports.SerialPort(&qu ...

  2. Bootstrap 历练实例-轮播(carousel)插件的事件

    事件 下表列出了轮播(Carousel)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 slide.bs.carousel 当调用 slide 实例方法时立即触发该事件. $(' ...

  3. UITableView 优化总结

    最近在微博上看到一个很好的开源项目VVeboTableViewDemo,是关于如何优化UITableView的.加上正好最近也在优化项目中的类似朋友圈功能这块,思考了很多关于UITableView的优 ...

  4. Apache 配置默认编码

    找到apache配置文件 httpd.conf ,找到以下内容 # # Specify a default charset for all content served; this enables # ...

  5. 四、Shell 数组

    Shell 数组 数组中可以存放多个值.Bash Shell 只支持一维数组(不支持多维数组),初始化时不需要定义数组大小(与 PHP 类似). 与大部分编程语言类似,数组元素的下标由0开始. She ...

  6. Linux-SSH远程登陆

    SSH是什么 Secure Shell 安全外壳协议 建立在应用层基础上的安全协议 可靠.转为远程登陆会话和其他网络提供安全性的协议 SSH客户端是用于多种平台 服务器安装SSH服务 安装:yum i ...

  7. centos7中使用LVM管理磁盘和挂载磁盘

    centos7使用LVM管理一块新的磁盘 注意!文中凡是带#的都是命令标志. 一些重要概念: LV(Logical Volume)- 逻辑卷, VG(Volumne Group)- 卷组, PV(Ph ...

  8. Mysql主从数据同步cheksum问题

    做主从同步时出现问题,show slave status显示错误: Last_IO_Error: Got fatal error from master when reading data from ...

  9. Oracle 数据库密码过期问题

    (1)在CMD命令窗口中输入:           sqlplus 用户名/密码@数据库本地服务名 as sysdba;(如:sqlplus scott/1234@oracle1 as sysdba; ...

  10. 用描述符实现缓存功能和property实现原理

    class Lazyproperty: def __init__(self, func): self.func = func def __get__(self, instance, owner): p ...