http://acm.hdu.edu.cn/showproblem.php?pid=4465
第一直觉概率DP但很快被否定,发现只有一个简单的二项分布,但感情的表达,没有对生命和死亡的例子。然后找到准确的问题,将不被处理,
事实上与思考C递归成为O(1)。每次乘以p
代码看这里http://fszxwfy.blog.163.com/blog/static/44019308201338114456115/
贴一个我没看懂的代码
//#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #include <map> #include <set> #include <queue> using namespace std; #define ls(rt) rt*2 #define rs(rt) rt*2+1 #define ll long long #define ull unsigned long long #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define CL(a,b) memset(a,b,sizeof(a)) #define IN(s) freopen(s,"r",stdin) #define OUT(s) freopen(s,"w",stdout) const ll ll_INF = ((ull)(-1))>>1; const double EPS = 1e-8; const double pi = acos(-1.0); const int INF = 100000000; double p1,p0; int n; double solve() { p1=1.0-p0; double tmpa,tmpb; tmpa=tmpb=1.0; double ans=0.0; int last=n+1; for(int i=0;i<n;i++) { if(i) { tmpa=tmpa*(n+i)*p0/i; tmpb=tmpb*(n+i)*p1/i; while(tmpa>n || tmpb>n) { tmpa*=p1; tmpb*=p0; last--; } } ans+=(n-i)*tmpa*pow(p1,last)+tmpb*(n-i)*pow(p0,last); } return ans; } int main() { //IN("hdu4465.txt"); int ic=0; while(~scanf("%d%lf",&n,&p0)) { printf("Case %d: %.6lf\n",++ic,solve()); } return 0; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4715037.html,如需转载请自行联系原作者