Xtu DP training B. Collecting bugs

Source: Internet
Author: User
Tags integer numbers
B. collecting busitime limit: 10000 msmemory limit: 64000kb64-bit integer Io format: % LLD Java class name: mainspecial judge 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 callthe 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 wocould take too long before the target cocould be reached. so Ivan and microhard agreed to use a simpler criteria --- Ivan shocould 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 wocould 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 particle 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. inputinput file contains two integer numbers, N and S (0 <N, S <= 1 000 ). outputoutput 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

Problem solving: probability DP, expect inverse push.

A software has s subsystems, which produce n kinds of bugs. One person finds a bug in one day. This bug belongs to a subsystem and belongs to a classification. The probability that each bug belongs to a subsystem is 1/s, the probability of a 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.

DP [I] [J] indicates that the I-type bug has been found. The expected DP [N] [s] = 0 indicates the number of days when the system bug has been found and the target State has been reached; the answer is DP [0] [0]; DP [I] [J] can be converted to the following four States: DP [I] [J], A bug is found to belong to the existing I classification and J systems. The probability is (I/n) * (J/s); DP [I] [J + 1]. It is found that a bug belongs to an existing category and does not belong to an existing system. the probability is (I/n) * (1-j/s); DP [I + 1] [J]. It is found that a bug belongs to an existing system and does not belong to an existing category, the probability is (1-I/n) * (J/s); DP [I + 1] [J + 1], and a bug is found not to belong to an existing system, does not belong to an existing classification. The probability is (1-I/n) * (1-j/s ).


 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long10 #define INF 0x3f3f3f11 using namespace std;12 const int maxn = 1010;13 double dp[maxn][maxn];14 int main(){15     int n,s,i,j;16     while(~scanf("%d%d",&n,&s)){17         dp[n][s] = 0;18         for(i = n; i >= 0; i--){19             for(j = s; j >= 0; j--){20                 if(i == n && j == s) continue;21                  dp[i][j]=(i*(s-j)*dp[i][j+1]+(n-i)*j*dp[i+1][j]+(n-i)*(s-j)*dp[i+1][j+1]+n*s)/(n*s-i*j);22             }23         }24         printf("%.4f\n",dp[0][0]);25     }26     return 0;27 }
View code

 

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.