[POJ2096] Collecting Bugs (Probabilistic DP)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=2096

The main problem: There are n kinds of bugs, there is a subsystem of S. A bug is found every day, belongs to a category and belongs to a subsystem. Ask you how many days each bug and each subsystem finds a bug.

Set DP[I][J] For now I have found a bug, within the J sub-system, to the desired number of days to the target State.

Dp[n][s] = 0, because n bugs have been found within the S sub-system, and no additional days are required.

DP[I][J] can be transferred to the following state:

DP[I][J]: Newly discovered bugs within J sub-systems that have been found in I species. Probability is: (i/n) * (J/S)

DP[I+1][J]: Newly discovered bugs are found in the category, but within the J sub-system that has been found. Probability is ((n-i)/N) * (J/S)

DP[I][J+1]: Newly discovered bugs in the discovered species, but not within the J sub-system already found. Probability is (i/n) * ((S-J)/s)

DP[I+1][J+1]: Newly discovered bugs are not found in the categories that have been discovered, and are not within the J sub-systems that have been discovered. Probability is ((n-i)/N) * ((S-J)/s)

State transitions:

DP[I][J] = dp[i][j] * (i/n) * (J/S) + dp[i+1][j] * ((n-i)/N) * (j/s) + dp[i][j+1]* (i/n) * ((S-J)/s) + dp[i+1][j+1] * ((n-i) /N) * ((S-J)/s) + 1

1 ///#pragma COMMENT (linker, "/stack:102400000,102400000")2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <vector>6#include <map>7#include <Set>8#include <bitset>9#include <cmath>Ten#include <numeric> One#include <iterator> A#include <iostream> -#include <cstdlib> -#include <functional> the#include <queue> -#include <stack> -#include <string> -#include <cctype> + using namespacestd; - #definePB push_back + #defineMP Make_pair A #defineSZ size () at #defineST begin () - #defineED End () - #defineCLR Clear () - #defineZERO (x) memset ((x), 0,sizeof (x)) -typedefLong LongLL; -typedef unsignedLong LongULL; intypedef pair<int,int>PII; - Const DoubleEPS = 1e-8; to  + Const intMax_n =1111; - intn,s; the DoubleF[max_n][max_n]; *  $ intMain () {Panax Notoginseng      while(~SCANF ("%d%d",&n,&s)) { -F[n][s] =0.0; the          for(inti=n;i>=0; i--){ +              for(intj=s;j>=0; j--){ A                 if(N*S==I*J)Continue; theF[I][J] =1.0* (f[i+1][j]* (n-i) *j+f[i][j+1]*i* (S-J) +f[i+1][j+1]* (n-i) * (S-J) +n*s)/(n*s-i*j); +             } -         } $printf"%.4f\n", f[0][0]); $     } -      -     return 0; the}

[POJ2096] Collecting Bugs (Probabilistic DP)

Related Article

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.