http://www.lydsy.com/JudgeOnline/problem.php?id=4008
We only need to ask each card to launch the probability of $p[i]$, and then multiply the damage value of each card $d[i]$ can.
In this $r$ wheel game, $f[i][j]$ says, there is the probability that the $j$ wheel game has ended before the first $i$ or the $i$ card.
Then there is the $r-j$ wheel game in the first $i$ card is not over.
Consider section $i+1$ card
If the rest of the $r-j$ wheel game, the first $i+1$ cards are not launched:
Probability is $ (1-p[i+1]) ^{r-j}$
Transfer to $f[i+1][j]$:
$f [i+1][j]+=f[i][j]* (1-p[i+1]) ^{r-j}$
If the rest of the $r-j$ wheel game, the first $i+1$ card in one of the innings launched:
Probability is $1-(1-p[i+1]) ^{r-j}$
Transfer to $f[i+1][j+1]$:
$f [I+1][j+1]+=f[i][j]*\{1-(1-p[i+1]) ^{r-j}\}$
At this time the probability of $i+1$ card $p[i+1]$ plus $f[i][j]*\{1-(1-p[i+1]) ^{r-j}\}$.
#include <cstdio>#include<cstdlib>#include<iostream>#include<fstream>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<map>#include<utility>#include<Set>#include<bitset>#include<vector>#include<functional>#include<deque>#include<cctype>#include<climits>#include<complex>//#include <bits/stdc++.h> for Cf,uoj, but not for POJ using namespaceStd;typedefLong LongLl;typedefDoubleDb;typedef pair<int,int>Pii;typedef Complex<DB>CP;#defineMmSt (a,v) memset (A,v,sizeof (a))#defineMmcy (A, B) memcpy (A,b,sizeof (a))#defineFill (a,l,r,v) Fill (a+l,a+r+1,v)#defineRe (I,A,B) for (i= (a); i<= (b); i++)#defineRed (i,a,b) for (i= (a); i>= (b); i--)#defineIRE (I,X) for (typedef (X.BEGIN ()) I=x.begin (); I!=x.end (); i++)#defineFi first#defineSe Second#defineM_p (A, B) Make_pair (A, B)#defineP_b (a) push_back (a)#defineSF scanf#definePF printf#defineBoth (k) (1<< (k))Template<classT>inline T Sqr (t x) {returnx*x;} Template<classT>inlinevoidUpmin (T &t,t tmp) {if(t>tmp) t=tmp;} Template<classT>inlinevoidUpmax (T &t,t tmp) {if(t<tmp) t=tmp;} InlineintSGN (DB x) {if(ABS (x) <1e-9)return 0;return(x>0)?1:-1;}ConstDB Pi=acos (-1.0);intGint () {intres=0;BOOLneg=0;CharZ; for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();} for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }ll Gll () {LL res=0;BOOLneg=0;CharZ; for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();} for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }Const intmaxn= -;Const intMaxr= the;intn,r;db P[MAXN+Ten],d[maxn+Ten];D b f[maxn+Ten][maxr+Ten],ans;db Power (DB A,intk) {DB x=1.0; while(k) {if(k&1) x*=a;a*=a;k>>=1;}returnx;}intMain () {Freopen ("bzoj4008.in","R", stdin); Freopen ("Bzoj4008.out","W", stdout); inti,j; for(intCase=gint (); case; case--) {n=gint (); r=Gint (); Re (i,1, N) scanf ("%lf%lf\n",&p[i],&D[i]); Re (i,0, maxn+Ten-1) Re (J,0, maxr+Ten-1) f[i][j]=0; Ans=0; f[0][0]=1; Re (i,0, N-1) Re (j,0, Min (i,r)) {DB tmp=power (1-p[i+1],r-j); F[i+1][j]+=f[i][j]*tmp; if(j+1<=r) {f[i+1][j+1]+=f[i][j]* (1-tmp); Ans+=f[i][j]* (1-TMP) *d[i+1]; }} PF ("%0.10lf\n", ans); } return 0; }
View Code
BZOJ4008[HNOI2015] King Arthur