Probability dp lightoj 1342

The meaning of problems: there are N stick, each stick has a weight which can identify a number of root, root several unrecognizable, recognizable able to get a stick, is not returned, the pumped unrecognizable, will put back and asked all sticks have been drawn at least once after weights and expectations

Unidentifiable stick, a uniform texture equivalent throwing dice, each face appears to ask at least one of a desired number of throws;

This question is used and the number of times each weight value occurs, it will be divided by the total number of times the number expected to throw, that is, the individual expectations throw count;

 1 #include <vector>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 #include <iostream>
 6 #include <algorithm>
 7 using namespace std;
 8 double f[5005];
 9 int main(){
10     double ans;
11     int i,j,n,x,y,t,cas;
12     f[0]=0;
13     for(i=1;i<=5000;i++)
 14      F [I] = F [I- . 1 ] + 1.0 / I;
 15      Scanf ( " % D " , & T);                              // with a labeled stick must be pumped only once 
16      for (CAS = . 1 ; CAS <= T; CAS ++) {                     // remaining on the situation is thesis, if 
. 17          Scanf ( " % D " , & n-);                          // weights are 1, each stick is desirably 
18 is          ANS = 0 ;                                   // . 1 /. 1. 1 + / 2 +. 1 /. 3. 1 + ... + / n- 
. 19          for (I = . 1; I <= n-; I ++) {                       // the value of the right stick is multiplied by each weight 
20 is              Scanf ( " % D% D " , & X, & Y);
 21 is              IF (Y == . 1 )
 22 is              ANS + = X;
 23 is              the else 
24              ANS + X * = F [n-];
 25          }
 26 is          the printf ( " Case% D: .5lf% \ n- " , CAS, ANS);
 27      }
 28      return  0 ;
 29 }

 

Guess you like

Origin www.cnblogs.com/pangbi/p/11614270.html