zoukankan      html  css  js  c++  java
  • 算法

    <?php
    header("Content-type: text/html; charset=utf-8");
    
    /**
     * +-----------------
     * | 阶乘
     * +-----------------
     */
    function factorial( $n ) {
        if ( 1 == $n ) return 1;
        $result = $n * factorial( $n - 1 );
        return $result;
    }
    //echo factorial( 5 );
    
    
    
    /**
     * +-----------------
     * 斐波那契数列
     * +-----------------
     */
    function fibonacci( $n ) {
        if ( 1 == $n || 2 == $n ) return 1;
        $result = fibonacci( $n - 1 ) + fibonacci( $n - 2 );
        return $result;
    }
    //echo fibonacci( 6 );
    
    
    
    /**
     * +-----------------
     * 汉诺塔
     * +-----------------
     */
    function hanoi( $n, $from, $depend, $to ) {
        if( 1 == $n ) {
            move( $n, $from, $to );
        } else {
            hanoi( $n - 1, $from, $to, $depend);
            move( $n, $from, $to );
            hanoi( $n - 1, $depend, $from, $to );
        }
    }
    #将第$n个圆盘,从$from柱子,移动到$to柱子
    function move( $n, $from, $to ) {
        echo '将' . $n . '号盘,从' . $from . '移动到' . $to . '<br/>';
    }
    //hanoi( 3, 'A', 'B', 'C' );
  • 相关阅读:
    HDU5772 (最小割)
    HDU 4971 (最小割)
    暑期集训个人赛1
    HDU 5644 (费用流)
    HDU5619 (费用流)
    暑假集训热身赛
    构建之法阅读笔记05
    找小水王
    找水王
    Runner站立会议之个人会议(冲刺二)
  • 原文地址:https://www.cnblogs.com/KTblog/p/5312091.html
Copyright © 2011-2022 走看看