Scout YYF I Topic Connection:
http://poj.org/problem?id=3744
Test instructions
There is a person to go to a place called "Mine Road", the route is a straight line, starting point in 1, the road has n mines, coordinates between [1, 100000000], this person each time have P (0.25≤p≤0.75) probability forward step, and have 1-p probability forward two steps, The probability that this cargo is safe to reach "mine road" through the minefield.
Exercises
By using the characteristic equation to find the expression of the general term, we have to walk through the place of Thunder (n+1) =f (n-1) * (1-p). PS: You can also use matrix to do fast power
About the characteristic equation
Code
/* Code slightly ugly do not spray */#include <stdio.h> #include <math.h> #include <algorithm>using namespace Std;const int n=15 ;d ouble pow3 (double a,long long B) {if (b==0) return 0; Double r=1,base=a; while (b!=0) {if (b&1) r*=base; Base*=base; b>>=1; } return R;} Long Long A[n],now;int main () {int N; Double res,a1,a2,r1,r2,c1,c2,p; while (~SCANF ("%d%lf", &n,&p)) {r1=p/2.0-sqrt (1.0-P+P*P/4); R2=P/2.0+SQRT (1.0-P+P*P/4); for (int i=0;i<n;++i) scanf ("%lld", &a[i]); Sort (a,a+n); now=1,res=1.0; for (int i=0;i<n;++i) {a1=res,a2=res*p; C2= (A1*R1-A2)/(R1*R2-R2*R2); c1= (A1-C2*R2)/r1; Res= (C1*POW3 (R1,a[i]-now) +c2*pow3 (R2,a[i]-now)); Res*= (1-P); now=a[i]+1; } printf ("%.7f\n", res); }}
POJ 3744:scout yyf I probability dp+ characteristic equation + fast power