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.

public class Solution {  //dp
public int integerBreak(int n) {
if(n==2) return 1;
if(n==3) return 2;
int[] dp=new int[n+1];
dp[0]=dp[1]=1;
dp[2]=2;dp[3]=3;
for(int i=4;i<=n;i++){
dp[i]=dp[1]*dp[i-1];
for(int j=2;j<=i/2;j++){
dp[i]=(dp[i]>dp[j]*dp[i-j])?dp[i]:dp[j]*dp[i-j];
}
}
return dp[n];
}
}

  

(dp)343. Integer Break的更多相关文章

  1. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  3. 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 ...

  4. Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs)

    Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs) 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost ...

  5. Leetcode之动态规划(DP)专题-931. 下降路径最小和(Minimum Falling Path Sum)

    Leetcode之动态规划(DP)专题-931. 下降路径最小和(Minimum Falling Path Sum) 给定一个方形整数数组 A,我们想要得到通过 A 的下降路径的最小和. 下降路径可以 ...

  6. Leetcode之动态规划(DP)专题-53. 最大子序和(Maximum Subarray)

    Leetcode之动态规划(DP)专题-53. 最大子序和(Maximum Subarray) 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. ...

  7. Leetcode之动态规划(DP)专题-1025. 除数博弈(Divisor Game)

    Leetcode之动态规划(DP)专题-1025. 除数博弈(Divisor Game) 爱丽丝和鲍勃一起玩游戏,他们轮流行动.爱丽丝先手开局. 最初,黑板上有一个数字 N .在每个玩家的回合,玩家需 ...

  8. Leetcode之动态规划(DP)专题-338. 比特位计数(Counting Bits)

    Leetcode之动态规划(DP)专题-338. 比特位计数(Counting Bits) 给定一个非负整数 num.对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数 ...

  9. #Week 11 - 343.Integer Break

    Week 11 - 343.Integer Break Given a positive integer n, break it into the sum of at least two positi ...

随机推荐

  1. Kafka Topic ISR不全,个别Spark task处理时间长

    现象 Spark streaming读kafka数据做业务处理时,同一个stage的task,有个别task的运行时间比多数task时间都长,造成业务延迟增大. 查看业务对应的topic发现当topi ...

  2. 关于ellipsis多行换行的方案

    WebKit浏览器或移动端的页面在WebKit浏览器或移动端(绝大部分是WebKit内核的浏览器)的页面实现比较简单,可以直接使用WebKit的CSS扩展属性(WebKit是私有属性)-webkit- ...

  3. matlab 批量提取CNN特征

    无类别,图像混合放置: clear close all addpath ./matlab model= './models/bvlc_reference_caffenet/deploy.prototx ...

  4. 【视频演示】FireBase链接已有应用&实时数据库的配置与使用

    全程无编辑,一镜到底,一帧未减,带上犯傻的时间全部不到31分钟:Firebase链接与基础功能使用如此之简单,跟我一起动手,从零开始链接Firebase吧~注意: 输入声源为笔记本自带麦克风,所以风扇 ...

  5. debain 8为Iceweasel安装flash播放器

    到adobe官网下载flash.或https://get.adobe.com/flashplayer/?loc=cn 下载tar.gz文件后,解压缩后会有一个libflashplayer.so 文件. ...

  6. SqlServer 触发器

    --创建insert类型的触发器create trigger tgr_product_insert   --创建触发器    on product --所针对的表    for insert --触发 ...

  7. (转) Spring框架笔记(二十五)——NamedParameterJdbcTemplate与具名参数(转)

    在经典的 JDBC 用法中, SQL 参数是用占位符 ? 表示,并且受到位置的限制. 定位参数的问题在于, 一旦参数的顺序发生变化, 就必须改变参数绑定. 在 Spring JDBC 框架中, 绑定 ...

  8. Tomcat编码配置解疑

    环境:tomcat6.0.23 jdk 1.6 相关参考: http://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html http://wiki.ap ...

  9. 基于OpenCV 的iOS开发

    1.创建项目 2.https://sourceforge.net/projects/opencvlibrary/files/opencv-ios/2.4.13/opencv2.framework.zi ...

  10. 深入理解Bindler

    Binder模型