Cf235 let's play Osu! [DP + probability]

Source: Internet
Author: User

Question:

For N positions, the probability pI of O occurrence at each position on 1-N is given. The scoring rules are as follows. x consecutive OSS records are x ^ 2 points, and the sum is calculated. For example, xxoooxooxx scores are as follows:

Expected score



Think about it. We can easily obtain the O (N ^ 2) method.

Make DP [I] The expected score of the former I

So


Obviously, this question


Consider how to change the score

We have


Then the scoring method becomes

Number of consecutive o pairs × 2 + O

One o can contribute 2 points


Now the score source is changed to two places

A pair of O (2 points) and a single O (1 point)


We know

Expectation = probability x benefit

We find the probability of each pair of O × 2

Find the probability of occurrence of a single O X

Sum is the expected score


For a certain vertex I

There are (1, I) (2, I) (3, I) (4, I )... (I-1, I) These pairs of O, each probability is from left to right concatenation, such

Make these probabilities equal to DP [I], that is

In this way, we have a recursive relationship.

For I + 1,


The sum of DP sum is the sum of all probabilities of occurrence of o x 2

+

Probability of a single o x 1

The expected score is obtained.


 
# Include <cstdio> # include <cstring> # include <cmath> # include <iostream> # include <algorithm> using namespace STD; const int nn = 111111; double f [NN]; double DP [NN]; int main () {# ifndef online_judgefreopen ("/home/raw.96/in.txt", "r", stdin ); # endifint N; scanf ("% d", & N); double sum = 0; For (INT I = 1; I <= N; I ++) {// CIN> F [I]; scanf ("% lf", & F [I]); sum + = f [I];} double ansum = 0; for (INT I = 2; I <= N; I ++) {DP [I] = (DP [I-1] + F [I-1]) * f [I]; ansum + = DP [I];} printf ("% F \ n", ansum * 2.0 + sum );}


Cf235 let's play Osu! [DP + probability]

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.