Codeforces Round #146 (Div. 2) D. Let's Play Osu!
来源:互联网 发布:windows下载 编辑:程序博客网 时间:2024/04/28 04:17
比赛的时候没有想出来,后来看了下思路,仔细研究后可以发现更多有用的东西
首先,考虑这样的问题,如果不是长度平方,仅仅是长度,那么期望是多少?
很显然是p1+p2+p3+····+pn,求解问题的麻烦之处就在于平方,看看数据量可以发现
这个题目最多接受nlogn算法,n*n就会超,求解这种期望类型的题目,大多采用dp的形式
但是这里状态很难控制且前后关系不够紧密,我的思考大概就到这,后来看的大牛的题解,
对于长度len,len*len=c(len,2)*2+len,所以sigma(len*len)=sigma(len)+sigma(c(len,2));
sigma(len) 是我们上面想的问题很简单 只需要将概率累加即可,下面考虑右半部分,右半部分相当于
k个 连续长度中leni中连续段的个数,听起来很抽象,我们可以看eg
oxoxooo ,在这个例子里面连续段只有3个 其他都是独立的 ,当长度只有1是len*len与len的期望是一致的
现在再用dp来解决这个问题,右半部分为总长度上连续段数的期望,令dp[i]表示1-i 连续段数(i必须为o)的期望
显然dp[1]=0; dp[2]=p1*p2,dp[3]=p2*p1*p3+p2*p3,我们可以发现这样一个事情,dp[i]=dp[i-1]*p[i]+p[i-1]*p[i],开始不太好理解
我们可以计算一下
dp[k]=p[1]*p[2]*p[3]····*p[k]+p[2]*p[3]*p[4]····*p[k]+p[3]*····*p[k]+```````+p[k-1]*p[k]
dp[k-1]=p[1]*p[2]*p[3]····*p[k-1]+p[2]*p[3]*p[4]····*p[k-1]+p[3]*····*p[k]+```````+p[k-2]*p[k-1]
显然dp[k]=dp[k-1]*p[k]+p[k-1]*p[k];
下面是代码
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<vector>#include<sstream>#include<string>#include<climits>#include<stack>#include<set>#include<bitset>#include<cmath>#include<deque>#include<map>#include<queue>#define iinf 0x7f7f7f7f#define linf 1000000000000000000LL#define dinf 1e200#define eps 1e-11#define all(v) (v).begin(),(v).end()#define sz(x) x.size()#define pb push_back#define mp make_pair#define lng long long#define sqr(a) ((a)*(a))#define pii pair<int,int>#define pll pair<lng,lng>#define pss pair<string,string>#define pdd pair<double,double>#define X first#define Y second#define pi 3.14159265359#define ff(i,xi,n) for(int i=xi;i<=(int)(n);++i)#define ffd(i,xi,n) for(int i=xi;i>=(int)(n);--i)#define ffl(i,r) for(int i=head[r];i!=-1;i=edge[i].next)#define ffe(i,r) for(_edge *i=head[r];i;i=i->next)#define cc(i,j) memset(i,j,sizeof(i))#define two(x) ((lng)1<<(x))#define lson l , mid , rt << 1#define rson mid + 1 , r , rt << 1 | 1#define mod 1073741824#define pmod(x,y) (x%y+y)%yusing namespace std;typedef vector<int> vi;typedef vector<string> vs;template<class T> inline void checkmax(T &x,T y){ if(x<y) x=y;}template<class T> inline void checkmin(T &x,T y){ if(x>y) x=y;}template<class T> inline T Min(T x,T y){ return (x>y?y:x);}template<class T> inline T Max(T x,T y){ return (x<y?y:x);}template<class T> T Abs(T a){ return a>0?a:(-a);}template<class T> inline T lowbit(T n){ return (n^(n-1))&n;}template<class T> inline int countbit(T n){ return (n==0)?0:(1+countbit(n&(n-1)));}double dp,ans,te,pre;int n;int main(){ while(scanf("%d",&n)==1) { ans=0; pre=0; dp=0; ff(i,1,n) { scanf("%lf",&te); ans+=te; dp=dp*te+pre*te; ans+=dp*2; pre=te; } printf("%.10lf\n",ans); } return 0;}
- Codeforces Round #146 (Div. 2) D. Let's Play Osu!
- Codeforces Round #146 (Div. 2) D. Let's Play Osu! comb数平方和的数学期望
- 解题报告:Codeforces Round #146 (Div. 1) B. Let's Play Osu! 概率DP
- codeforces 235B - Let's Play Osu!
- Codeforces 235B. Let's Play Osu!
- Codeforces 235B Let's Play Osu!
- CodeForces 235B Let's Play Osu!
- Codeforces 235B Let's Play Osu! 概率dp(水
- codeforces 235B Let's Play Osu! 概率dp
- Codeforces 235B Let's Play Osu! (概率)
- CodeForces 235B Let's Play Osu!(概率dp)
- Codeforces 235B Let's Play Osu! 概率dp
- codefrces 235B Let's Play Osu!
- CF235 Let's Play Osu![dp+概率]
- Codeforces 235B Let's Play Osu! (概率dp求期望+公式变形)
- codeforces 235B. Let's Play Osu! (概率与期望DP)
- CF 235B Let's Play Osu!(概率dp)
- CF 235B Let's Play Osu!(概率dp)
- 在vc6.0中除数为零的验证
- 图片显示和内存释放
- Linux线程属性总结
- case when then else
- cocos2d-x滚动文字(一)
- Codeforces Round #146 (Div. 2) D. Let's Play Osu!
- jQuery 遍历 - nextUntil() 方法 及 prevUntil()方法
- linux时间服务器ntp及内网同步
- ubuntu下安装SQLite
- Windows8 Metro/Modern 官方应用
- 程序在内存中的分布
- UML顺序图笔记
- windows 8 邮件
- C#中using的三种用法