Poj 2096 collecting bugs (probability DP)

Source: Internet
Author: User
/* Expectation of DP inverse recursive solution: a software has s sub-systems, which produce n kinds of bugs. Someone finds a bug one day. This bug belongs to a sub-system, the probability that a bug belongs to a subsystem is 1/s. The probability of a bug belongs to a certain classification is that 1/N queries discover n kinds of bugs, and each subsystem is expected to discover the number of days of the bug. Solution: DP [I] [J] indicates that the I-type bug has been found. The J-system bug indicates the expected DP [N] [s] = 0 for the number of days to reach the target State, DP [0] [0] is the answer to the question DP [I] [J] is converted from four States to 1: DP [I] [J] finds that a state already has I classification, and the probability of J systems p1 = I/N * j/S 2: DP [I + 1] [J] does not belong to this category, but belongs to this system bug probability P2 = (1-I/n) * j/S 3: DP [I] [J + 1] found to belong to this system, but does not belong to this classification of bug probability P3 = I/N * (1-j/s) 4: DP [I + 1] [J + 1] is found to belong to this system and does not belong to this classification of bug probability P4 = (1-I/n) * (1-j/s) So: DP [I] [J] = p1 * DP [I] [J] + p2 * DP [I + 1] [J] + P3 * DP [I] [J + 1] + P4 * DP [I + 1] [J + 1] + 1; simplified: DP [I] [J] = (DP [I + 1] [J] * (N * j-I * j) + dp [I] [J + 1] * (I * s-I * j) + dp [I + 1] [J + 1] * (N * s-J * n-I * s + I * j) + N * s) /(n * s-I * j); */# include <stdio. h> # include <algorithm> # include <string. h ># include <iostream> using namespace STD; double DP [1010] [1010]; int main () {int N, S, I, j; while (~ Scanf ("% d", & N, & S) {// memset (DP, 0, sizeof (DP )); DP [N] [s] = 0; for (I = N; I> = 0; I --) {for (j = s; j> = 0; j --) {if (I = N & J = s) continue; DP [I] [J] = (DP [I + 1] [J] * (N * j-I * j) + dp [I] [J + 1] * (I * s-I * j) + dp [I + 1] [J + 1] * (N * s-J * n-I * s + I * j) + N * s) /(n * s-I * j);} printf ("%. 4lf \ n ", DP [0] [0]);} return 0 ;}

Poj 2096 collecting bugs (probability DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.