Stone scissors step (rps): dp, probability & expectations

Std since it has been given a direct throw the code it. Code comment is good clatter.

Because I am also a bit ignorant, they do not understand or have different opinions must be sprayed me in the comments area ah!

1 #include <. Bits / STDC ++ H>
 2  a using  namespace std;
 3  // first meaning of the questions may be people wrong. Title mean to you based on a few opponents were a few stone scissors to decision
 4  // rather than the end of the battle you will be able to know each other who specifically which directly infer the remainder of the 
5  #define GF [ I] [J] [K] // pressure line, and in the solution to a problem that is not the same meaning, but had no effect 
. 6  #define D (X, K) for (int X = K; X> = 0; - X) // pressure lines, many words 
. 7  int n-; Double X [ 51 is ] [ . 4 ], F [ 51 is ] [ 51 is ] [ 51 is ] [ . 4 ], ANS, C [ 51 is ] [ 51 is ];
 . 8 // F arrays meanings: when the last dimension of 1 to 3 show a first i + j + k + 1 individual person in front of the i-1, j a 2, k 3 of a case where the 1 to 3, probability
 9  // indicates when the last dimension is 0 before the i + j + k individual an i-1, j a 2, k 3-probability, i.e., the problem solution where g array 
10  int main () { 
 . 11      Scanf ( " % D " , & n-); F [ 0 ] [ 0 ] [ 0 ] [ 0 ] = . 1 ; // initialization 
12 is      for ( int I = . 1 ; I <= n-; I ++) Scanf ( " % %% LF LF LF " , & X [I] [ . 1 ], & X [I] [ . 3 ], & X [I] [ 2 ]),
 13 is          X [I] [ . 1] / = 300 , X [I] [ 2 ] / = 300 , X [I] [ . 3 ] / = 300 ;
 14      // read probability is noted that the order of 132. The stones are abstracted as scissors step 123, it wins a win 2,2 3,3 wins 1 
15      for ( int I = 0 ; I <= 50 ; I ++) C [I] [ 0 ] = 1 ;
 16      for ( int I = . 1 ; I <= 50 ; I ++) for ( int J = . 1 ; J <= I; J ++) C [I] [J] = C + [I- . 1 ] [J- . 1 ] + C [I- . 1 ] [J];
 . 17      //Pascal's Triangle. Note: to use 50! Level without modulo, to open so long long or Double 
18 is      for ( int S = . 1 ; S <= n-; ++ S) D (I, S) D (J, Si) D (K, Sij) D (U, (i + J + k == s? 0 : 3 )) { // bit like a backpack
 19          // you can put s alone to open a one-dimensional array to represent the presently considered to be the first of several people, better understand but seemingly memory will fry
 20          // u is 1 to 3, respectively enumeration of a few people, a few people in front of 1,2,3, this person out u
 21          // note u enumeration is when i + j + k! = s if the next update other probability 123, or updating only the probability of reaching a state of
 22          // overall probability (i.e., solution to a problem in the array g) u 0 is calculated to reach this state 
23 is          IF (I) g [U] + = F [I- 1 ] [J] [K] [U] * X [s] [ 1 ]; // this person out of 1 s, the cumulative probability of
 24          @When when u = 0, f [i] [j] [k] [0] from the f [i-1] [j ] [k] [0] from the transfer (u = 0 does not consider the next person What)
 25          // a new state is the one in the original state, which is the probability of x [s] [1]. G is calculated it is not necessary to consider the influence of other array values f
 26          // because there meaning according to f [i] [j] [ k] [0] = f [i] [j] [k] [1] + f [i ] [J] [K] [2] + F [I] [J] [K] [. 3]
 27          // when u> 0 to not the same, the calculated probability is 1 in the next
 28          // it is the other side out of the last round of probability multiplied by the other party is really a cumulative probability come, this time i + j + k! s =
 29          // because this stuff you ever fill it up as a backpack opponents to update its probability
 30          // meaning is probably "The current status is already so the next round and you come across a s", then you s contribution to the probability of generating
 31          // so the probability is that you come to the original state, multiplied by the probability of s 1, s is the probability of the current state of contributions
 32          // so i + j + k == s not enumerate when to 3, since the original state which corresponds to your personal s have, but you are just considering individual s-ah 
33 is          IF (J) G [U] = F + [I] [J- . 1 ] [K] [u] * x [s] [2 ]; // a 2, supra 
34 is          IF (K) G [U] = F + [I] [J] [- K- . 1 ] [U] * X [S] [ 3 ]; // out of three, with 
35          IF (U) G [U] = F + [I] [J] [K] [ . 1 - . 1 ] * X [S] [U]; // do not control the 1-1, it is only to the width font neatly under
 36          // this is to make up for the above defects. This layer transfer. No matter what the current status is that anyway, the first person is a u s a
 37          // above is not repeated. S is in a Contribution to the previous state, that is to say s contribution to the current state 
38 is      }
 39      D (I, N- . 1 ) D (J, N- . 1 -i) D (K, nij- . 1 ) // i + J + k do not enumerate to n, n as it has been carried out after the next round once again not matter what the score is not 
40         ANS + = max (max (G [ . 1 ] + . 3 * G [ 2 ], G [ 2 ] + . 3 * G [ . 3 ]), G [ . 3 ] + . 3 * G [ . 1 ]) / C [n-] [I J + K +] / (nij- K);
 41 is      // optimal decision time in each state (i.e., the opponent has been determined that the i-1, j a 2, k 3 a) has a uniquely determined you next to a
 42      // every time when decisions are accumulated score, corresponding to the three kinds of decisions are 1,2,3.g [1] and a tie that is, 3 * g [2] is the beat 2
 43 is      // you said optimal decision is based on available information (each opponent out what), what will be the next rival by guessing the decision to weigh in 3
 44      // as to why use a number of combinations: as you count the probability just to reach the probability of this step, but you are from n people casually elected c [n] [i + j + k] personal
 45      // but in fact the same one game for the same i + j + k you can only choose one time, when you calculate the probability added together, and now requires an average of
 46      //Then in addition to a (nijk) causes almost, because you are from the rest of the (nijk) elected in a personal challenge to
 47      // This step is the probability 1 / (nijk), but you cycle on top of layer 5 when not considered, so here uniform removal of 
48      printf ( " % .12lf \ the n- " , ANS); // to be used in the std% .12f output double, really surprise 
49 } // to delete all comments you will find out that only 21 lines of code 811B

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/11331121.html