"URAL 1776" Anniversary Firework (probability DP)

Source: Internet
Author: User
Tags fread

"URAL 1776" Anniversary Firework (probability DP)

Main topic:
N Rockets (3 <= n <= 4) are lined up for the first time to ignite the first and last, followed by the probability of igniting a rocket each time between all neighboring lighted rockets. Each two times the ignition between the interval of 10s, each ignition of a few rockets as the same time lit. Ask for the desired total interval of time.

The first idea completely deviated from ... Consider the interval DP: DP[I][J] Dp[i][j] represents the expectation of the waiting time of the rocket that ignites the i~j. But the expectation is to accumulate instead of taking the maximum value, so the interval DP is completely wrong ... (Though I'm not consciously feeling it right ....)

The positive solution is to consider dp[i][j] for igniting a continuous I rocket, with the probability of ≤j \le J times.

This transfer is actually
Dp[i][j]=dp[i][j−1]+∑1≤k≤i (dp[k−1][j−1]∗dp[i−k][j−1]−dp[k−1][j−2]∗dp[i−k][j−2])/(i) dp[i][j] = dp[i][j-1]+\sum\ Limits_{1 \le k \le i} (Dp[k-1][j-1]*dp[i-k][j-1]-dp[k-1][j-2]*dp[i-k][j-2])/(i)
Using the probability theory, that is, enumerating the current I rocket state, igniting the K-rockets, and finally lit I rockets with ≤j \le J times probability.
≤j \le J-Times benefits right here, dp[k−1][j−1]∗dp[i−k][j−1]−dp[k−1][j−2]∗dp[i−k][j−2] dp[k-1][j-1]*dp[i-k][j-1]-dp[k-1][j-2]*dp[ I-K][J-2] can be said to ignite the left side of the K and K rockets to the right, and eventually wait for the probability of j-1 times. That is, left and right side is j-1 times, the other side ≤j−1 \le j-1 times the probability.

Then accumulate the following expectations to ignite N-2 rockets

The code is as follows:

#include <iostream> #include <cmath> #include <vector> #include <cstdlib> #include <cstdio > #include <climits> #include <ctime> #include <cstring> #include <queue> #include <stack&
Gt  #include <list> #include <algorithm> #include <map> #include <set> #define LL Long Long #define Pr pair<int,int> #define FREAD (CH) freopen (CH, "R", stdin) #define FWRITE (CH) freopen (CH, "w", stdout) using namespace s
td
const int INF = 0X3F3F3F3F;
const int mod = 1E9+7;
Const double EPS = 1e-8;

const int MAXN = 444;

Double DP[MAXN][MAXN];
    int main () {//fread ("");

    Fwrite ("");

    int n;
    scanf ("%d", &n);

    N-= 2;

    for (int i = 0, I <= N; ++i) for (int j = i; j <= N; ++j) dp[i][j] = 1;

        for (int len = 2; Len <= n; ++len) {double b = len;
            for (int j = 2; j <= Len; ++j) {dp[len][j] = dp[len][j-1];
   for (int k = 1; k <= Len; ++k)         {Dp[len][j] + = (Dp[len-k][j-1]*dp[k-1][j-1]-dp[len-k][j-2]*dp[k-1][j-2])/b;
        }//printf ("num:%d cnt:%d%f\n", Len,j,dp[len][j]);

    }} double ans = 0;

    for (int i = 1; I <= n; ++i) ans = ans+ (dp[n][i]-dp[n][i-1]) *i*10;

    printf ("%.11f\n", ans);
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.