【POJ - 2096】Collecting Bugs(概率dp)

题干:

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

题目大意:

一个软件有s个子系统,会产生n种bug。某人一天一定会发现一个bug,这个bug属于某种bug,发生在某个子系统中。求找到所有的n种bug,且每个子系统都找到bug,这样所要的天数的期望。

解题报告:

需要注意的是:bug的数量是无穷大的,所以发现一个bug,出现在某个子系统的概率是1/s,属于某种类型的概率是1/n。

又有:期望可以分解成多个子期望的加权和,权为子期望发生的概率,即 E(aA+bB+...) = aE(A) + bE(B) +...

以下题解来自kuangbin:

dp[i][j]表示已经找到i种bug,j个系统的bug,达到目标状态的天数的期望dp[n][s]=0;要求的答案是dp[0][0];dp[i][j]可以转化成以下四种状态:dp[i][j],发现一个bug属于已经有的i个分类和j个系统。概率为(i/n)*(j/s);dp[i][j+1],发现一个bug属于已有的分类,不属于已有的系统.概率为 (i/n)*(1-j/s);dp[i+1][j],发现一个bug属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(j/s);dp[i+1][j+1],发现一个bug不属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(1-j/s);整理便得到转移方程

注意不能用注释的那个代码,因为没有整理,所以等号左侧和右侧都有dp[i][j],这样是不行的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,s;
double dp[1555][1555];
int main()
{cin>>n>>s;dp[n][s]=0;for(int i = n; i>=0; i--) {for(int j = s; j>=0; j--) {if(i == n && j == s) continue;
//			dp[i][j] = 1 + dp[i+1][j] * (n-i)*j/n/s + dp[i][j] * i*j/n/s + dp[i][j+1] *i*(s-j)/n/s + dp[i+1][j+1]*(n-i)*(s-j)/n/s;dp[i][j]=((n-i)*j*dp[i+1][j]+(n-i)*(s-j)*dp[i+1][j+1]+i*(s-j)*dp[i][j+1]+n*s)/(n*s-i*j);}}printf("%.4f\n",dp[0][0]);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440076.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Django框架(展示图书信息简易版)

Linux环境下 创建虚拟环境 在python3中&#xff0c;创建虚拟环境 mkvirtualenv -p python3 虚拟机名称 mkvirtualenv -p python3 py_django查看创建的虚拟环境 workon退出当前的虚拟环境 deactivate 删除虚拟环境&#xff08;不要做&#xff09; rmvirtualenv 虚拟机名称 …

吴恩达机器学习作业(五):支持向量机

目录 1&#xff09;数据预处理 2&#xff09;Scikit-learn支持向量机 3&#xff09;决策边界比较 4&#xff09;非线性SVM 5&#xff09;最优超参数 6&#xff09;垃圾邮件过滤器 在本练习中&#xff0c;我们将使用支持向量机&#xff08;SVM&#xff09;来构建垃圾邮件分…

一些关于ROS中move_base的理解

move_base是ROS下关于机器人路径规划的中心枢纽。它通过订阅激光雷达、map地图、amcl的定位等数据&#xff0c;然后规划出全局和局部路径&#xff0c;再将路径转化为机器人的速度信息&#xff0c;最终实现机器人导航。这里又要盗官网的图了。 上面这个图很好的展示了move_base的…

机器学习笔记(十四):异常检测

目录 1&#xff09;Problem motivation 2&#xff09;Gaussian distribution 3&#xff09;Algorithm 4&#xff09;Developing and evaluating an anomaly detection system 5&#xff09;Anomaly detection vs. supervised learning 6&#xff09;Choosing what featur…

【Gym - 101606F】Flipping Coins(概率dp)

题干&#xff1a; Here’s a jolly and simple game: line up a row of N identical coins, all with the heads facing down onto the table and the tails upwards, and for exactly K times take one of the coins, toss it into the air, and replace it as it lands eith…

python图书管理系统

以下三个文件需在同一目录下。json文件格式不能更改 books-fxm.json [{"name": "图书管理","author": "fxm","price": "99999"},{"name": "完美世界","author": "辰东"…

ROS actionlib学习(一)

actionlib是ROS中一个很重要的功能包集合&#xff0c;尽管在ROS中已经提供了srevice机制来满足请求—响应式的使用场景&#xff0c;但是假如某个请求执行时间很长&#xff0c;在此期间用户想查看执行的进度或者取消这个请求的话&#xff0c;service机制就不能满足了&#xff0c…

python 基础知识

- python语言特点 简单、易学、高级 面向对象 免费和开源 边编译边执行 &#xff1a;python是解释型语言&#xff0c;边编译边执行。 丰富的库 : python拥有许多功能丰富的库。 胶水语言 : 可以拼接c&#xff0c;c&#xff0c;java等语言 可移植 &#xff1a; python能运行在不…

机器学习笔记(十五):推荐系统

目录 1&#xff09;Problem formulation 2&#xff09;Content-based recommendations 3&#xff09;Collaborative filtering 4&#xff09;Collaborative filtering algorithm 5&#xff09;Vectorization: Low rank matrix factorization 6&#xff09;Implementation…

*【CodeForces - 280C】Game on Tree(期望模型,期望的线性性)

题干&#xff1a; Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree. The game consists of several steps. On each step, Momiji chooses…

武侠风云(基础版)

基本任务&#xff1a; 1 建立角色类&#xff0c;角色拥有生命值的属性和攻击的方法&#xff0c;攻击值是随机的。 2 建立职业子类&#xff0c;刀客&#xff0c;&#xff08;伤害少&#xff0c;血量多&#xff09;剑客&#xff08;伤害正常&#xff0c;血量正常&#xff0c;有几…

机器学习笔记(十六):大规模机器学习

目录 1&#xff09;Learning with large datasets 2&#xff09;Stochastic gradient descent 3&#xff09;Mini-batch gradient descent 4&#xff09;Stochastic gradient descent convergence 1&#xff09;Learning with large datasets 回顾一下我们之前提到的这句…

【ZOJ - 3329】One Person Game(带循环的概率dp,数学期望,高斯消元,数学)

题干&#xff1a; There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces. All the dice are fair dice, so the probability of rolling each value, 1 to K1, K…

智能聊天机器人系统

# 智能聊天机器人系统 # 1.系统简介 # 随着社会的各个公司以及大学对人工智能技术的深入研究和快速发展&#xff0c;人工智能技术将逐步应用到 # 方方面面。智能聊天机器人系统是基于各类传感器收集人类语音数据&#xff08;智能电视、智能空调&#xff0c; # 智能冰箱、智能音…

机器学习笔记:总结

下面是我们本课程学到的要点&#xff1a; 1&#xff09;监督学习&#xff1a;线性回归&#xff0c;逻辑回归&#xff0c;神经网络&#xff0c;SVM&#xff1b; 2&#xff09;无监督学习&#xff1a;k均值&#xff0c;PCA&#xff0c;异常检测 3&#xff09;特别应用&#xf…

ROS探索总结(十二)——坐标系统

在机器人的控制中&#xff0c;坐标系统是非常重要的&#xff0c;在ROS使用tf软件库进行坐标转换。 相关链接&#xff1a;http://www.ros.org/wiki/tf/Tutorials#Learning_tf 一、tf简介 我们通过一个小小的实例来介绍tf的作用。 1、安装turtle包 <span>$ rosdep instal…

【BZOJ - 3036】绿豆蛙的归宿(概率DAG图dp,拓扑排序,概率dp,期望的线性性)

题干&#xff1a; 随着新版百度空间的下线&#xff0c;Blog宠物绿豆蛙完成了它的使命&#xff0c;去寻找它新的归宿。 给出一个有向无环的连通图&#xff0c;起点为1终点为N&#xff0c;每条边都有一个长度。绿豆蛙从起点出发&#xff0c;走向终点。 到达每一个顶点时&#x…

python菜鸟100例精选

# 有四个数字&#xff1a;1、2、3、4&#xff0c;能组成多少个互不相同且无重复数字的三位数&#xff1f;各是多少&#xff1f; def four_number():n 0for i in range(1,5):for j in range(1,5):for k in range(1,5):if (i ! j) and (i!k) and (j!k):n 1# print(i,j,k)print(…

机器学习笔记:Overview

1&#xff09;机器学习笔记&#xff08;1&#xff09;&#xff1a;Introduction 2&#xff09;机器学习笔记&#xff08;2&#xff09;&#xff1a;单变量线性回归 3&#xff09;机器学习笔记&#xff08;3&#xff09;&#xff1a;线性代数回顾 4&#xff09;机器学习笔记&…

【LightOJ - 1030】Discovering Gold(概率dp,数学期望,期望的线性性)

题干&#xff1a; You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice …