这应该属于几何分布里的东西,标程的意思尚未理解
1 #include <iostream>
2 #include <cstdio>
3
4 using namespace std;
5
6 int n;
7 double d[1001], Pl, Pr;
8
9 main() {
10 while( cin >> n >> Pl >> Pr && n) {
11 d[0] = 0.0;
12 for( int i = 1; i <= n; i++ ) {
13 d[i] = 1e50;
14 for( int j = 0; j < i; j++ )
15 d[i] <?= d[j] + d[i-j-1] + 1 + // do left, right, then middle
16 (1/(1-Pl-Pr) - 1) * // E(knocking down middle)
17 ((Pl*d[j] + Pr*d[i-j-1])/(Pl+Pr) + 1);
18 // cost of knocking down middle
19 }
20 printf( "%.2lf\n", d[n] );
21 }
22 }
23
标程2
1 #include <math.h>
2 #include <stdio.h>
3
4 double Pl, Pr, C[1100], c; // C[m] is cost to build m in a row
5
6 int i,l,k,m,n,r;
7
8 main(){
9 while (3 == scanf("%d%lf%lf",&n,&Pl,&Pr)) {
10 if (Pl+Pr == 0) {
11 printf("%d.00\n",n);
12 continue;
13 }
14 C[0] = 0;
15 for (i=1;i<=n;i++) C[i] = 1e19;
16 for (m=1;m<=n;m++) {
17 for (l=0;l<m;l++) { // l dominoes on the left
18 r = m-l-1;
19 c = 1 + C[l] + C[r] +
20 (1/(1-Pr-Pl)-1) * (1+ Pl/(Pr+Pl)*C[l] + Pr/(Pr+Pl)*C[r]);
21 if (c < C[m]) C[m] = c;
22 }
23 }
24 printf("%0.2lf\n",C[n]);
25 }
26 }
27
对概率太陌生,一些概率题先放这
So you want to be a 2n-aire?
Dumb Bones
Practice
posted on 2009-02-21 12:54
wangzhihao 阅读(294)
评论(0) 编辑 收藏 引用