该题目来源于牛客网《剑指offer》专题。

给你一根长度为n的绳子,请把绳子剪成整数长的m段(m、n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],…,k[m]。请问k[0]xk[1]x…xk[m]可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为2、3、3的三段,此时得到的最大乘积是18。

输入一个数n,意义见题面。(2 <= n <= 60)

输出答案。

Go语言实现:

func cutRope(n int) int {
if n<2 || n > 60 {
return 0
}
if n == 2 {
return 1
}
if n == 3 {
return 2
}
if n == 4 {
return 4
}
return 3*cutRopeHandler(n-3)
} func cutRopeHandler(n int) int {
if n == 2 {
return 2
}
if n == 3 {
return 3
}
if n == 4 {
return 4
}
return 3*cutRopeHandler(n-3)
}

最新文章

  1. 微信小程序 开发 微信开发者工具 快捷键
  2. 旅行计划-DAG上最长路
  3. 理解Flight框架核心
  4. jQuery on()方法绑定动态元素的点击事件无效
  5. DirectX 9 UI三种设计学习笔记:文章4章Introducing DirectInput+文章5章Wrapping Direct3D
  6. 服务端套接字类CxServerSocket的使用
  7. AngularJs学习笔记0——前言
  8. NPOI导出excel(带图片)
  9. AsyncLocal的运作机制和陷阱
  10. 网络协议 3 - 从物理层到 MAC 层
  11. GT sport真实赛道详解 - Brands Hatch | 伯蘭士赫治GP賽車場
  12. input[type=file]上传文件(格式判断、文件大小、上传成功后操作)
  13. [转]decorators.xml的用法
  14. 解决pycharm添加第三方包失败
  15. Django的认证系统—auth模块
  16. suricata 原文记录
  17. OpenStack的架构详解[精51cto]
  18. jq中each的中断
  19. c++ 类的构造顺序
  20. column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd.

热门文章

  1. schedule of 2016-09-26~2016-10-02(Monday~Sunday)——1st semester of 2nd Grade
  2. Vim的环境设定与记录
  3. UGUI源码之EventSystem
  4. 获取当前URL
  5. macOS 10.11.* 安装scrapy
  6. LeetCode 第七题--整数反转
  7. ORM批量添加
  8. Qt Installer Framework翻译(3-5)
  9. V模型
  10. 修改 Apache 的默认端口