博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取某行某列的值
阅读量:6921 次
发布时间:2019-06-27

本文共 606 字,大约阅读时间需要 2 分钟。

$row) { return 0; } $tmp_arr = []; for ($i=1; $i<=$row; $i++) { for ($j=1; $j<=$col; $j++) { if ($j == 1 || $j== $i) { $tmp_arr[$i][$j] = 1; } else { $tmp_arr[$i][$j] = $tmp_arr[$i-1][$j] + $tmp_arr[$i-1][$j-1]; } } } return $tmp_arr[$row][$col];}echo getVal(6,2);/** * 获取某行某列的值(递归方式) * * @param $row 行数 * @param $col 列数 * @return number */function getVal2($row, $col){ if ($col > $row) { return 0; } if ($col==1 || $col==$row) { return 1; } else { return getVal2($row-1,$col-1) + getVal2($row-1,$col); }}echo getVal2(6,2);

 

输入某行某列,返回其值,注意防止死递归(太简单了,丢人丢到家了)

 

转载地址:http://ufecl.baihongyu.com/

你可能感兴趣的文章
初学vue整理
查看>>
threejs中矩阵旋转原理
查看>>
Spring事务管理
查看>>
初学Vue
查看>>
Android Studio (一. 安装)
查看>>
20170625-bind方法的实现
查看>>
重拾css(8)——盒子模型
查看>>
Web图片资源的加载与渲染时机
查看>>
Python3基础数据类型
查看>>
vue 插件
查看>>
HTML表格的运用
查看>>
jstatd 启动报错解决:Could not create remote object
查看>>
MYSQL新特性secure_file_priv对读写文件的影响
查看>>
发布 Google Chrome 插件教程
查看>>
linux中如何让进程在后台运行
查看>>
react源码解析003 - 关于eslint
查看>>
nodejs-local-api
查看>>
规范开发工具
查看>>
Perfect Rectangle
查看>>
Linux下常见文件系统对比
查看>>