Poj 2096 collecting bugs (expected)

Source: Internet
Author: User

Http://poj.org/problem? Id = 2096



Program bugs include N Subsets and S types. Each bug belongs to each subset with a probability of 1/N, and each bug belongs to each species with a probability of 1/S. It is expected that every subset has a bug.


Expectation. If DP [I] [J] is set, the existing bug belongs to the subset of I and the expectation of J categories. The final state is known as DP [N] [s] = 0, DP [I] [J] can be reversed:

DP [I] [J]. The new bug belongs to J categories of the existing I subsets, with the probability of I/N * j/s;

DP [I] [J + 1]. The new bug belongs to the existing subset of I but does not belong to the existing J categories, the probability is I/N * (1-J/s );

DP [I + 1] [J]. The new bug does not belong to an existing subset of I but belongs to an existing J classification. The probability is (1-I/n) * j/s;

DP [I + 1] [J + 1]. The new bug does not belong to an existing subset of I or belongs to an existing J classification. The probability is (1-I/N) * (1-J/s );

Therefore, DP [I] [J] = I/N * j/S * DP [I] [J] + I/N * (1-J/s) * DP [I] [J + 1] + (1-I/n) * j/S * DP [I + 1] [J] + (1-I/N) * (1-J/s) * DP [I + 1] [J + 1] + 1.


# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h> # include <algorithm> // # define ll _ int64 # define ll long # define EPS 1e-12 # define PI ACOs (-1.0) using namespace STD; const int INF = 0x3f3f3f; const int maxn = 4010; double DP [1010] [1010]; int main (){ Int N, S; while (~ Scanf ("% d", & 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] = (DP [I + 1] [J] * (N-I) * j + dp [I] [J + 1] * I * (S-j) + dp [I + 1] [J + 1] * (N-I) * (S-j) + N * s)/(n * s-I * j) * 1.0;} printf ("%. 4f \ n ", DP [0] [0]);} return 0 ;}


Poj 2096 collecting bugs (expected)

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.