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