http://www.lydsy.com/JudgeOnline/problem.php?id=4008 (Topic link)
Test instructions
Given n skills, each skill is released in order with the possibility of p[i], which can cause d[i] damage. Each game can only launch a skill, ask R wheel game expected to cause damage.
Solution
Just half an afternoon of DP, but WA a tune, tune and WA, found the entire DP are withered, and then deleted the rewrite ... Helpless, looked at the puzzle.
http://blog.csdn.net/vmurder/article/details/46461649
Get a new pose for expectation ...
Code
bzoj4008#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <cmath> #define LL long long#define inf 1<<30#define Pi acos ( -1.0) #define Free (a) Freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int Maxn=500;int d[maxn],n,r; Double P[MAXN],F[MAXN][MAXN];d ouble power (double A,int b) {double res=1;while (b) {if (b&1) res*=a;b>>=1;a*=a;} return res;} int main () {int t;scanf ("%d", &t), while (t--) {memset (f,0,sizeof (f)); scanf ("%d%d", &n,&r); for (int i=1;i <=n;i++) scanf ("%lf%d", &p[i],&d[i]); f[0][r]=1;double ans=0;for (int i=1;i<=n;i++) for (int j=1;j<=r; J + +) {f[i][j]=f[i-1][j]*power (1-p[i-1],j) +f[i-1][j+1]* (1-power (1-p[i-1],j+1)); ans+=f[i][j]* (1-power (1-p[i],j)) * D[i];} printf ("%.10lf\n", ans);} return 0;}
"Bzoj4008" hnoi2015-King Arthur