Week 11 - 343.Integer Break

Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.

For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).

Note: You may assume that n is not less than 2 and not larger than 58.

Credits:

Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

my solution:

class Solution {
public:
int integerBreak(int n) {
int dp[n + 1];
dp[0] = 0;
dp[1] = 1;
dp[2] = 1;
dp[3] = 2;
dp[4] = 4;
for (int i = 5; i <= n; ++i) {
dp[i] = 3 * max(i - 3, dp[i - 3]);
}
return dp[n];
}
};

#Week 11 - 343.Integer Break的更多相关文章

  1. LN : leetcode 343 Integer Break

    lc 343 Integer Break 343 Integer Break Given a positive integer n, break it into the sum of at least ...

  2. 【LeetCode】343. Integer Break 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学解法 动态规划 日期 题目地址:https:// ...

  3. 343. Integer Break -- Avota

    问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...

  4. [LeetCode] 343. Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  5. (dp)343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  6. Leetcode 343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  7. 343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  8. leetcode@ [343] Integer Break (Math & Dynamic Programming)

    https://leetcode.com/problems/integer-break/ Given a positive integer n, break it into the sum of at ...

  9. LeetCode题解 343.Integer Break

    题目:Given a positive integer n, break it into the sum of at least two positive integers and maximize ...

随机推荐

  1. Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” a...

    报错: 从错误信息来看,似乎需要通过管理员身份来接受许可协议,于是试着从这个角度google,终于在这里找到了解决方法: 1.打开终端,输入  sudo xcodebuild -license 2.终 ...

  2. vue 防抖和节流

    函数防抖(debounce):当持续触发事件时,一定时间段内没有再触发事件,事件处理函数才会执行一次,如果设定的时间到来之前,又一次触发了事件,就重新开始延时. 函数节流(throttle):当持续触 ...

  3. mail - 发送和接收邮件

    SYNOPSIS(总览) mail [-iInv ] [-s subject ] [-c cc-addr ] [-b bcc-addr ] to-addr... mail [-iInNv -f ] [ ...

  4. Tensorflow fintune

    https://zhuanlan.zhihu.com/p/42183653 tf2.0中有更简单的做法,和keras一样

  5. shell中switch语法

    转载: https://blog.csdn.net/love__coder/article/details/7262160

  6. Linux openssh8.0p1升级步骤

    前期准备开启本机telnet服务,以防openssh升级失败无法连接服务器.注:redhat 5 6 和 redhat7 开机启动配置相关文件不同,请注意 1.安装zlibtar -xzvf zlib ...

  7. shell之文本过滤(grep)

    shell之文本过滤(grep) 分类: linux shell脚本学习2012-09-14 14:17 588人阅读 评论(0) 收藏 举报 shell正则表达式扩展工具存储 grep(全局正则表达 ...

  8. ubuntu重装--备份/配置

    https://github.com/wenlin-gk/document/blob/master/ubuntu%E5%A4%87%E4%BB%BD%2B%E9%85%8D%E7%BD%AE.txt

  9. Redis---系统学习

    1.安装Redis Docker 2.查看Redis配置 进入Docker中的Redis容器: 进入启动命令目录:cd /usr/local/bin/ 启动redis客户端:./redis-cli c ...

  10. __new__与__init__的区别

    __new__  : 控制对象的实例化过程 , 在__init__方法之前调用 __init__ : 对象实例化对象进行属性设置 class User: def __new__(cls, *args, ...