<?php
/**
 * Notes:
 * User: liubing17
 * DateTime: 2019-10-17 17:10
 */
function get($m, $n){
    /*
     * 获取m*n矩阵正方形的个数
     * */
    if($m*$n <=0 ){
        return 0;
    }
    $total = 0;
    while($m>0 && $n>0){
        $total += $m*$n;
        $m--;
        $n--;
    }
    return $total;
}
echo get(1,1).PHP_EOL;

    m*n 矩阵中求正方形个数

 

 

m*n矩阵(宽为m单位长度,长为n单位长度)所构成的正方形个数=边长为1,2,3 ...min(m,n)时正方形个数的总和

  边长为1时:宽 有m种选法,高有n种选法,总共有m*n种选法

 边长为2时:宽有m-1种选法,高有n-1种选法,总共有(m-1)*(n-1)种选法

 ...

边长为x(x=min(m,n))时:宽有m-x种选法,高有n-x种选法,总共有(m-x)*(n-x)种选法

一次循环即可

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2021-12-17
  • 2021-05-11
  • 2021-05-19
  • 2022-12-23
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-08-15
  • 2022-12-23
相关资源
相似解决方案