Bzoj 4008 "HNOI2015" King Arthur

Source: Internet
Author: User

Title Link: King Arthur

This problem is good god tat ... Sure enough, my DP is still too weak ...

First thought for a half-day direct DP to expect, the final result of WA's unintelligible ...

Finally went through the puzzle, and then found that the probability of first, and then seek the expectation ... New posture \ (get\).

We may as well consider the \ (r\) wheel as a r\ opportunity, and then make \ (f_{i,j}\) to think about the former \ (i\) card, but also the probability of \ (j\) chance.

Then we have a few more chances for the $i$ card, enumeration, and consider it alone:

If this card does not start, then the probability is $f_{i-1,j}* (1-p_i) ^j$

If this card is launched on the remaining $j$, the probability is $f_{i-1,j+1}* (1-p_i) ^j $, as each card is launched at most once.

and the probability that the $i$ card will be launched when there is $j$ chance is $f_{i-1,j+1}* (1-p_i) ^j $

So preprocess out $ (1-p_i) ^j$, push the past can.

Paste the following code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #define FILE (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout) #define N 230using namespace std; typedef double Llg;int T,N,R,A[N];LLG p[n],f[n][n],mi[n][n],ans;int main () {File ("a"), scanf ("%d", &t); for (int i=0; i<n;i++) Mi[0][i]=mi[i][0]=1;while (t--) {scanf ("%d%d", &n,&r), ans=0;for (int i=1;i<=n;i++) {scanf ("%lf %d ", &p[i],&a[i]); mi[i][1]=1-p[i];for (int j=2;j<=r+1;j++) mi[i][j]=mi[i][j-1]* (1-p[i]);} for (int i=0;i<=r;i++) f[0][i]=0;for (int. i=0;i<=n;i++) f[i][r+1]=0;f[0][r]=1;for (int i=1;i<=n;i++) for (int j= 0;j<=r;j++) {f[i][j]=f[i-1][j]*mi[i][j];f[i][j]+=f[i-1][j+1]* (1-mi[i][j+1]); ans+=f[i-1][j+1]* (1-mi[i][j+1]) * A[i];} printf ("%.10lf\n", ans);} return 0;}

  

Bzoj 4008 "HNOI2015" King Arthur

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.