Java- popped order

Planet X special attention to the order, all the roads are one-way street.

Beetle a fleet of 16 vehicles, according to the grid has numbers , sandwiched between other traffic, slowly forward.
Roadside dead end, only by receiving a car, temporary checkpoints, as shown in FIG.

Planet X is too rigid, required per passing vehicle must enter the checkpoint , may not be allowed to go check, it may double check.
If the order of vehicles entering and leaving the inspection stations may be arbitrarily interleaved . Then, after the team hit the road again, the order may be how many?

For convenience, assume checkpoints can accommodate any number of cars .
Obviously, if the team only one car, you may order one kind; 2 car may order two kinds; 3 car may order five kinds.

Thinking

Clearly, in this form, it is difficult to write recursive call similar structures, such as f (16) and f (15) of recurrence relations, because the argument is not enough. So we give a state, it can push the sole representative of current vehicle and wait for the case, then it should contain at least two parameters: how many cars waiting outside the stack onto the stack; a total of how many cars stack.

There are two cases when considering the recursive: into an a, not into but out. I.e., f (a-1, b-1) + f (a, b-1).

An outlet: a is 0, the order of only one stack; B is 0 (this condition is written on the back, this time excluding a == 0), subtracts the a 1, b 1 becomes. When the first two conditions are not met, return f (a-1, b-1) + f (a, b-1).

Source:

 

operation result:

Guess you like

Origin www.cnblogs.com/Cocoon-z/p/12208400.html