#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 ...
随机推荐
- Response笔记
# 今日内容 1. HTTP协议:响应消息 2. Response对象 3. ServletContext对象 ## HTTP协议: 1. 请求消息:客户端发 ...
- [IIS]修改MaxFieldLength与MaxRequestBytes彻底解决Request Too Long的问题
当 IIS7/7.5 收到的请求头的长度超过16K(默认值),就会引发"Bad Request - Request Too Long. HTTP Error 400. The size of ...
- Codeforces Round #427 (Div. 2) - A
题目链接:http://codeforces.com/contest/835/problem/A 题意:两个人给网站发信息,现在给出信息的长度n,两个人的延迟和打字速度(一个字符),问网站先收到哪个人 ...
- HTML与CSS中的定位个人分享
定位 static - 默认值 (几乎不用,了解就可以) absolute - 绝对定位,不为元素预留空间,脱离文档流: 如果当前元素的父级元素是<body>元素的话 -> 是相对于 ...
- 基于VSFTP的本地YUM源及光盘YUM源搭建
基于VSFTP的本地YUM源及光盘YUM源搭建 一.yum环境的本地源搭建(基于VSFTP): 1)安装vsftp; *********************************** ...
- SpringBoot整合MyBatis-Plus代码自动生成类
在springboot的test测试类下创建 MpGenerator.java 配置 MpGenerator.java public class MpGenerator { @Test publ ...
- Pytorch详解NLLLoss和CrossEntropyLoss
是什么? https://www.cnblogs.com/marsggbo/p/10401215.html 具体pytorch怎么运算的 https://blog.csdn.net/qq_222102 ...
- 用 IDEA工具导入SVN项目。 步骤一:选择VCS
Intellij IDEA是目前主流的IDE开发工具,工程项目导入也是必不可少的操作,本文讲述如何用 IDEA工具导入SVN项目. 步骤一:选择VCS 步骤二:打开SVN Repositories 在 ...
- 判断div里面的子集是否含有特定的类
if($('#BankCardId .card').length){ alert("请绑定银行卡"); } if ($('#user-20130011 #age-20130011' ...
- [UVA160]Factors and Factorials 题解
前言 这道题目本身毫无技术含量珂言,但是输出格式珂以调一年 题解 这道题让我们求\(N!\)中每个质数的个数. 一种方法是直接模拟,枚举\(N!\)中的每个元素,然后暴力查看每个数含有有多少质数. 但 ...