#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 ...
随机推荐
- getchar、putchar、puts、gets
getchar(字符) 输入获取一个字符 putchar(字符) 输出控制台一个字符 scanf()格式化输入 printf() 格式化输出 gets(arr) 输入一个字符串给已经声明的数组ar ...
- git flow 基础了解
git flow 软件开发中的一个分支管理流程.利用它可以让软件开发有条不紊的进行,先对它进行一个大概的了解吧,后面工作了实际用到了在深入研究一下. 先看下它的工作流程: 这张图看着一脸茫然,先放在这 ...
- 简单的物流项目实战,WPF的MVVM设计模式(二)
往Models文件添加一个类,ConnectObject /// <summary> /// 链接数据库字符串 /// </summary ...
- 前端开发HTML&CSS入门——具体是做什么的
软件开发,一提起来感觉这个感觉这个词范围很大很广,说起来也很笼统.不知所云,开发的到底是什么?或者说开发的具体内容是什么?以前我们讲软件开发主要是分前端和后端,那前端和后端又是什么那?你可以这么通俗的 ...
- svn版本服务器的搭建和简单使用
⼀ 服务器搭建篇 1 在”应⽤用程序”⽂文件夹下,找到”实⽤用⼯工具”,打开”终端”APP 2 运⾏行svnadmin create repository,运⾏行完毕之后,可以在当前⺫⽬目录下找 到⼀ ...
- Apache 的 http-default.conf 详解
##Apache 默认设置文件 Timeout 300 #设置服务器在断定请求失败前等待的秒数.默认值 300 KeepAlive Off #设置是否启用 HTTP 持久链接,On ...
- 01.Linux-CentOS系统清理缓存脚本
#自动清理缓存脚本 [root@k8s-node3 ~]# vim freemem.sh#! /bin/sh#当前已使用内存大小used=`free -m | awk 'NR==2' | awk '{ ...
- nodejs 操作 mysql
1.安装插件 npm install mysql 2.调用代码 var mysql = require('mysql') var connection = mysql.createConnection ...
- Linux架构之Nginx 常见问题
第54章 Nginx常见问题 一.Nginx多Sever优先级 在开始处理一个http请求时,nginx会取出header头中的Host变量,与nginx.conf中每个server的server_n ...
- bzoj3631: [JLOI2014]松鼠的新家(树上差分)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3631 题目大意:给定含有n个顶点的树,给定走遍整棵树顺序的序列a[1],a[2],a[3 ...