标签:padding ios sso cpp add names double ble 1.2
#include <stdio.h>
int main()
{
puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/46461649");
}
然后
有的时候反过来想,比方求选的概率。记录不选的概率可能会更好一些。
再比方这道题。不从前面递推,而考虑
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
long double ans;
long double p[233],d[233],f[233][333];
long double power(long double x,int p)
{
long double ret=1.0;
while(p)
{
if(p&1)ret*=x;
x*=x,p>>=1;
}
return ret;
}
int main()
{
freopen("test.in","r",stdin);
int i,j,T;
double a,b;
for(scanf("%d",&T);T--;)
{
memset(f,0,sizeof f);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%lf%lf",&a,&b);
p[i]=a,d[i]=b;
}
f[0][m]=1.0,ans=0.0;
for(i=1;i<=n;i++)for(j=1;j<=m;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",(double)ans);
}
return 0;
}
标签:padding ios sso cpp add names double ble 1.2
原文地址:http://www.cnblogs.com/gavanwanggw/p/7260094.html