传送门
题意:给定\(n\)个概率,表示每一位是1的概率,连续\(x\)个1对答案的贡献为\(x^3\),问贡献的期望是多少
解答:考虑DP,用\(E[x]\)表示在x位置的分数的期望,我们很容易得到\(E[(x+1)^3-x^3]=E[3x^2+3x+1]\),对这个式子利用概率公式展开,得到递推式\(E[x^3]=E[(x-1)^3]+3*E[(x-1)^2]+3*E[x-1]+1\),同理,得到二次方的公式\(E[(x+1)^2-x^2]=E[2x+1]\),从而得到\(E[x^2]=E[(x-1)^2]+2*E[x]+1\),分别表示出\(E[x]\)和\(E[x^2]\)和\(E[x^3]\)期望即可,这里的期望是前面连续1的个数的期望乘上\(p[i]\)对应的就是每一个位置的期望了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
/************************************************************************* >>> Author: WindCry1 >>> Mail: lanceyu120@gmail.com >>> Website: https://windcry1.com >>> Date: 12/30/2019 11:03:37 PM *************************************************************************/ //#pragma GCC optimize(2) //#pragma GCC diagnostic error "-std=c++11" #include <cstring> #include <cmath> #include <cstdio> #include <cctype> #include <cstdlib> #include <ctime> #include <vector> #include <iostream> #include <string> #include <queue> #include <set> #include <map> #include <algorithm> #include <complex> #include <stack> #include <bitset> #include <iomanip> #include <list> #include <sstream> #include <fstream> #if __cplusplus >= 201103L #include <unordered_map> #include <unordered_set> #endif #define endl '\n' #define ALL(x) x.begin(),x.end() #define MP(x,y) make_pair(x,y) #define ll long long #define ull unsigned long long #ifdef WindCry1 #define DEBUG(x) cout<<#x<<" : "<<x<<endl; #endif #define lowbit(x) x&(-x) #define ls u<<1 #define rs u<<1|1 using namespace std; template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;} template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;} template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);} template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);} typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<double,double> pdd; const double eps = 1e-8; const int INF = 0x3f3f3f3f; const int mod = 1e9+7; const int dir[4][2]={-1,0,1,0,0,-1,0,1}; double p[100010],s1[100010],s2[100010],s3[100010]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #ifdef WindCry1 freopen("C:/Users/LENOVO/Desktop/in.txt","r",stdin); #endif int n;cin>>n; for(int i=1;i<=n;i++) cin>>p[i]; for(int i=1;i<=n;i++){ s1[i]=(s1[i-1]+1)*p[i]; s2[i]=(s2[i-1]+2*s1[i-1]+1)*p[i]; s3[i]=s3[i-1]+(3*s2[i-1]+3*s1[i-1]+1)*p[i]; } cout<<fixed<<setprecision(1)<<s3[n]<<endl; return 0; } |
0 条评论