Jumping lattice problem--Ali written test

Source: Internet
Author: User

There are,...... Infinite lattice, you start from the 1th lattice, each time 1/2 probability of jumping forward a square, 1/2 probability of jumping forward two squares, go to the lattice number of multiples of 4 to end, the end of the expected walk of the number of ____.
    • 2
    • 12/5
    • 14/5
    • 16/5
    • 18/5
    • 4

This problem, it is obvious that the question of recursion:define the expected value of step (i,j) for lattice I, J;Step (1,4) is expected to jump from the first to the third, to the four, you can only go to the second lattice (expected 0.5* (step +1)) or a three (expected 0.5* (step (1,3) +1)) , where 1 means it takes 1 steps to jump to the 4th grid after reaching 2nd or 3rd. therefore there areStep (1,4) =0.5* (step +1) +0.5* (step (1,3) +1) =1+0.5* (step +Step (1,3)) same with step (1,3) =1+0.5*step (All) +0.5*step (+) step (=1+0.5*step) +0.5*step (1,4) step (=0) Simultaneous equations, get step (1,4) is expected to be 18/5, select E.
You can also use a computer to calculate probabilities, such as:
/** * Project Name: * File Description: * Main Features: * Version number: 1.0 * Producer: LCX * creation time: 2015-8-25 **//** * @author LCX * */public class Pacetest {static random rand=new random ();p ublic static int pace () {return (int) (rand.nextdouble () *2+1);} public static void Main (string[] args) {Double sum=0;int times=10000;//experiment 10,000 times for (int i=0;i<times;i++) {int index=1; int Pace=0;while (index%4!=0) {index+=pace ();p ace++;} Sum+=pace;} SYSTEM.OUT.PRINTLN ("Expected value:" +sum/times);}} 
cross-examine 1, if the subject is starting from 2, then what is expected?
same method: step (2,4) =1+0.5*step (3,4) step (2,3) =0.5+0.5* (1+step (2,1)) step (2,1) =1+0.5*step (2,3) +0.5*step (2,4) Step (2,2) =0Finally find step (2,4) =12/5
Cross-Examine 2, if the subject is a multiple of 3 to stop, then what is expected? The same method calculates that the expected value is 2.
In the final analysis, the use of recursive thinking. Similar topics include frog jumping problems, tiling problems (programming beauty), and so on.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Jumping lattice problem--Ali written test

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.