POJ 3744:scout yyf I probability dp+ characteristic equation + fast power

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.