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. CSS3新特性学习

    1.一些实用规范:盒子模型,列表模块,超链接方式,语言模块,背景和边框,文字特效,多栏布局: 2:新增的选择器selctor eg: 1) 子元素过滤伪类:div:first-child  (自动识别 ...

  2. gcc编译的四个阶段:预处理,编译,汇编,链接

    1:gcc编译的四个阶段:预处理,编译,汇编,链接 #vi file.c #gcc -E file.c -o file.i//-E查看且预处理后停止编译,-o生成目标文件,-i表示已预处理 #gcc  ...

  3. 如何关闭emacs开启时自己打开的欢迎界面

    EMACS在开启后,会自动打开一个欢迎界面.如果要去除他,可以在用emacs或其实编辑工具编辑~/.emacs文件. 在最下面一行加上,保存退出即可. (setq inhibit-startup-me ...

  4. 关于ArcGis的二次开发-基于ArcEngine10.2(内有安装包)

    网上很少有arcgis engine10.2的安装包,在这里我把安装包链接附上,是百度云,有需要的可以自己下--http://pan.baidu.com/s/1mhIhYYG 顺带着把arcgis d ...

  5. ASP.NET中Cookies的使用

    准备开始写后台代码了,不过刚看到cookies就傻眼了,网上搜集了一些资料,总结了一下,初学者可以看看. 创建COOKIES System.Web.HttpCookie cookie=new Http ...

  6. Android的Notification使用注意事项

    看<Android开发-第一行代码>这本书,读到创建系统通知(Notification)的时候,发现若干主要方法均已经过期,于是找了一下官方的开发指南,进入此url:http://deve ...

  7. ionic tab导航在android 真机测试中 导航在顶部解决办法

    1.打开app.js文件 2.找到.config(function($stateProvider, $urlRouterProvider)){ $stateProvider ... ... } 3.加 ...

  8. 基于jQuery的email suggest插件

    最近项目中有表单提交的地方需要用户填写邮箱,PM(产品经理)和运营都强烈要求在用户填写邮箱的时候出现suggest列表,简化用户输入的填写流程.我考虑了下,这个应该也是经常会用到的功能,细心的朋友可能 ...

  9. 空的安卓工程添加activity

    1.编写类继承activity,并重写onCreate方法 package org.tonny; import android.app.Activity; import android.os.Bund ...

  10. C#编程总结(十四)dynamic

    http://www.cnblogs.com/yank/p/4177619.html C#编程总结(十四)dynamic 介绍 Visual C# 2010 引入了一个新类型 dynamic. 该类型 ...