面试题 台阶
一个台阶有13层,每次跨一步或者两步,从底层到最高层,有多少种走法?
<?php
static $count=0;
static $step=array();
for($i=1;$i<=13;$i++){
for($j=0;$j<=6;$j++){
if($i*1+$j*2==13){
$count++;
$step[]=[$i,$j];
}
}
}
var_dump($count);
echo "<pre/>";
var_dump($step);
?>
int 7
array (size=7)
0 =>
array (size=2)
0 => int 1
1 => int 6
1 =>
array (size=2)
0 => int 3
1 => int 5
2 =>
array (size=2)
0 => int 5
1 => int 4
3 =>
array (size=2)
0 => int 7
1 => int 3
4 =>
array (size=2)
0 => int 9
1 => int 2
5 =>
array (size=2)
0 => int 11
1 => int 1
6 =>
array (size=2)
0 => int 13
1 => int 0