#Week 11 - 343.Integer Break
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的更多相关文章
- 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 ...
- 【LeetCode】343. Integer Break 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学解法 动态规划 日期 题目地址:https:// ...
- 343. Integer Break -- Avota
问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...
- [LeetCode] 343. Integer Break 整数拆分
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- (dp)343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- Leetcode 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 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 ...
- LeetCode题解 343.Integer Break
题目:Given a positive integer n, break it into the sum of at least two positive integers and maximize ...
随机推荐
- SpringCloud入门(二)
ribbon实现负载均衡 上文只是将服务注册到eureka上,但是consumer还是硬编码调用,前文也有提到这种硬编码方式肯定是不合理的,一来服务上线之后,IP地址肯定是变动的, 再则,采用硬编码的 ...
- sublime text 3基本参数设置及插件使用
sublime text 3常用基本设置,包括插件,字体等一些配置.写个随笔,备忘. soda主题:特别喜欢: 插件:Color Highlighter输入颜色时,可以看到颜色. 在Color Hig ...
- Gcc如何知道文件类型。
Linux系统不区分扩展名,但是GCC编译器通过扩展名区分. GCC是根据扩展名来编译源文件的.
- Matlab 2019a 下载和安装步骤
目录 1. 安装包下载 + 多套数学建模视频教程 2. 安装步骤 1. 安装包下载 + 多套数学建模视频教程 参考:https://blog.csdn.net/COCO56/article/detai ...
- apachectl 命令详解-graceful 不中断原有连接,重新启动 Apache 服务器
apachectl(Apache control interface) 参 数: fullstatus 显示服务器完整的状态信息. graceful 重新启动 Apac ...
- md5sum - 计算检验MD5效验码
总览 (SYNOPSIS) ../src/md5sum [OPTION] [FILE]... ../src/md5sum [OPTION] --check [FILE] 描述 (DESCRIPTION ...
- Listview使用
ListView控件比前面几种控件要复杂一些,通过此控件,可将项目组成带有或不带有列标头的列,并显示伴随的图标和文本.ListView控件是由ColumnHeader和ListItem对象所组成的,其 ...
- LeetCode--096--不同的二叉搜索树(python)
我的思路比较low直接看官方题解吧... class Solution: def numTrees(self, n: int) -> int: G = [0] * (n+1) G[0],G[1] ...
- jquery 父,子,兄弟节点获取
jquery 父,子,兄弟节点获取 jQuery.parent(expr) //找父元素 jQuery.parents(expr) //找到所有祖先元素,不限于父 ...
- Android App学习计划
模块化 Json Gson Fastjson Jackson EventBus GreenDao Flutter ButterKnife Dagger okhttp Rxjava/Rxandroid ...