UV-1498 Activation (DP + probability)

Source: Internet
Author: User

UV-1498 Activation (DP + probability)

Description

After 4 years 'waiting, the game "Chinese Paladin 5" finally comes out. tomato is a crazy fan, and luckily he got the first release. now he is at home, ready to begin his journey. but before starting the game, he must first activate the product on the official site. there aretoo implements passionate fans that the activation server cannot deal with all the requests at the same time, so all the players must wait in queue. each time, the server deals with the request of the first player in the queue, and the result may be one of the following, each has aprobability:


Activation failed: This happens with the probability of p1. The queue remains unchanged and the server will try to deal with the same request the next time. connection failed: This happens with the probability of p2. Something just happenedand the first player in queue lost his connection with the server. the server will then remove his request from the queue. after that, the player will immediately connect to the server againand starts queuing at the tail of the queue. activation succeeded: This happens with the probability of p3. Congratulations, theplayer will leave the queue and enjoy the game himself. service unavailable: This happens with the probability of p4. Something just happened and the server is down. the website must shutdown the server at once. all the requests that are still in the queue will never be dealt.

Tomato thinks it sucks if the server is down while he is still waiting in the queue and there are no moreK-1 guys before him. And he wants to know the probability that this uugly thing happens.


To make it clear, we say three things may happen to Tomato: he succeeded activating the game; the server is down while he is in the queue and there are no moreK-1 guys before him; the server is down while he is in the queue and there are at leastKGuys before him. Now you are to calculate the probability of the second thing.

Input

There are no more than 40 test cases. Each case in one line, contains three integers and four real numbers:N,M(1MN2000 ),K(K1 ),P1,P2,P3,P4 (0P1,P2,P3,P41,P1 +P2 +P3 +P4 = 1), indicating there areNGuys in the queue (the positions are numbered from 1N), And at the beginning Tomato is atMTh position, with the probabilityP1,P2,P3,P4 mentioned above.

Output

A real number in one line for each case, the probability that the uugly thing happens.

The answer shocould be rounded to 5 digits after the decimal point.

Sample Input

2 2 1 0.1 0.2 0.3 0.43 2 1 0.4 0.3 0.2 0.14 2 3 0.16 0.16 0.16 0.52

Sample Output

0.304270.232800.90343 question: there are n people waiting in queue to activate the game on the official website. Tomato ranks at the MB. For the first person in the queue. There is a situation: 1. activation failed, stayed in the queue and waited for the next activation (probability p1) 2. Lost connection, went out of the queue, and ranked last in the queue (probability p2) 3. Activation successful. Exit the queue (Probability: p3). 4. The server is paralyzed. The server is stopped and cannot be activated by anyone. When the server crashes, the Tomato's position in the queue is <= k. The idea is: kuangbinGG writes well, so I won't talk about the problem of using kuangbinGG for reference:
Probability DP; Set dp [I] [j] to indicate I individual queuing, and Tomato to the position j to reach the target (j <= I) dp [n] [m] is for j = 1: dp [I] [1] = p1 * dp [I] [1] + p2 * dp [I] [I] + p4; 2 <= j <= k: dp [I] [j] = p1 * dp [I] [j] + p2 * dp [I] [J-1] + p3 * dp [I-1] [J-1] + p4; k
  
   
N recursive solution dp [I]. dp [I-1] is equivalent to a constant when dp [I] is solved. After solving dp [I] [1 ~ I] When the following I equation j = 1: dp [I] [1] = p * dp [I] [I] + c [1]; 2 <= j <= k: dp [I] [j] = p * dp [I] [J-1] + c [j]; k
    
    
#include 
     
      #include 
      
       #include 
       
        #include #include 
        
         using namespace std;const int maxn = 2020;const double eps = 1e-5;double c[maxn], f[maxn], dp[maxn][maxn];int main() {int n, m, k;double p1, p2, p3, p4;while (scanf("%d%d%d%lf%lf%lf%lf", &n, &m, &k, &p1, &p2, &p3, &p4) != EOF) {if (p4 < eps) {printf("0.00000\n");continue;}double p = p2/(1-p1);double p41 = p4/(1-p1);double p31 = p3/(1-p1);f[0] = 1.0;for (int i = 1; i <= n; i++)f[i] = p * f[i-1];dp[1][1] = p41 / (1-p);c[1] = p41;for (int i = 2; i <= n; i++) {for (int j = 2; j <= k; j++) c[j] = p31 * dp[i-1][j-1] + p41;for (int j = k+1; j <= i; j++) c[j] = p31 * dp[i-1][j-1];double tmp = c[1] * f[i-1];for (int j = 2; j <= i; j++)tmp += c[j] * f[i - j];dp[i][i] = tmp / (1 - f[i]);dp[i][1] = p * dp[i][i] + c[1];for (int j = 2; j < i; j++)dp[i][j] = p * dp[i][j-1] + c[j];}printf("%.5lf\n", dp[n][m]);}return 0;}
        
       
      
     


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.