Test instructions, there are two ways of selling tickets. One is ICPC one is the other way ICPC the probability of success is twice times the other way ...
Then a man showed up and he knew the two ways to rob a ticket. How many people he wants to know if he is using ICPC to rob a ticket the probability of success is how much the probability of success with ACM Rob votes ...
Do not have a lot of probability DP is still groping ...
DP[I][J] On behalf of the first round of J Icpc people already have tickets ...
Of course, I-j also have tickets for other ways to rob the ticket. This is the same function to search two times the principle ...
Optimizing I<=a Once is to put the initialization in the for ...
The first time to see the problem of this card ...
The optimization of the DP array is placed in the for ...
1#include <stdio.h>2#include <iostream>3#include <algorithm>4#include <math.h>5#include <string.h>6#include <string>7#include <map>8#include <vector>9#include <queue>Ten #defineM (A, B) memset (A,b,sizeof (a)) One using namespacestd; A Doubledp[3005][3005];//I round J have tickets - BOOLok=false; - DoubleSolveintAintBintc) { the DoubleN= (Double) A; - DoubleIcpc= (Double) b; - DoubleAcm= (Double) C; - if(N>ICPC+ACM) n=icpc+ACM; + if(a>b+c) a=b+C; -dp[0][0]=1; + for(intI=1; i<=n;i++){ Adp[i][0]=0;//optimization initialization is over. atdp[i][0]+=dp[i-1][0]* (acm-i+1.0)/(acm-i+1.0+icpc*2.0); - } - for(intI=1; i<=n;i++){ -dp[i][i]=0; -dp[i][i]+=dp[i-1][i-1]* ((icpc-i+1.0)*2.0)/(acm+ (icpc-i+1.0)*2.0); - } in for(intI=2; i<=n;i++){ - for(intj=1; j<i&&j<=a;j++){ todp[i][j]=0; +dp[i][j]+=dp[i-1][j]* (acm-(i-j-1.0))/(acm-(i-j-1.0) + (ICPC-J) *2.0);//Here you can also optimize -dp[i][j]+=dp[i-1][j-1]* ((icpc-j+1.0)*2.0)/(acm-(I-J) + (icpc-j+1.0)*2.0); the } * } $ Doubleans=0;Panax Notoginseng for(intI=0; i<=n&&i<=a;i++) - if(OK) ans+= (Dp[a][i]) *i/ICPC; the Elseans+= (Dp[a][i]) * (n-i)/ACM; + returnans; A } the + intMain () { - intN,ICPC,ACM; $ while(~SCANF ("%d",&N)) { $ if(n==0) Break;//It 's not supposed to be here . -scanf"%d%d",&icpc,&ACM); - if(icpc==0&&acm==0){ theprintf"1.0000000000000000\n"); -printf"1.0000000000000000\n");Wuyi Continue; the } -ok=true; Wuprintf"%.16lf\n", Solve (n,icpc+1, ACM)); -ok=false; Aboutprintf"%.16lf\n", Solve (n,icpc,acm+1)); $ } - return 0; -}
uvalive 6672 Bonus Cards probability dp