日期:2013-05-20 浏览次数:20505 次
<?php
//一个楼梯有n个台阶,每次上一个或两个台阶,共有多少种上法, 每种走法的步骤是什么样的.
define('TOTLE_STEP', 10);
$p = '';
$obj = new step($p, 0, 0);
$obj->go();
class step{
var $parent;
var $count;
var $step;
var $son1;
var $son2;
function step(&$parent, $step, $count){
$this->parent = &$parent;
$this->step = $step;
$this->count = $count + $step;
}
function go(){
if($this->count==TOTLE_STEP)
$this->callback();
if($this->count<=TOTLE_STEP-1){
$this->son1 = new step($this, 1, $this->count);
$this->son1->go();
}
if($this->count<=TOTLE_STEP-2){
$this->son2 = new step($this, 2, $this->count);
$this->son2->go();
}
}
function callback($str=''){
if($this->parent!=null){
$str = $this->step.$str;
$this->parent->callback('--'.$str);
}else{
echo $str.'<br>';
}
}
}
?>