Integer Break
2016-05-01 20:12
513 查看
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).
For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).
class Solution { public: int integerBreak(int n) { int* arr; arr = new int[n + 1]; arr[1] = 1; int temp; for(int i = 2; i <= n; i++){ temp = i - 1; for(int j = 2; j <= i / 2; j++){ if(j * arr[i - j] > temp) temp = j * arr[i - j]; if(j * (i - j) > temp) temp = j * (i - j); } arr[i] = temp; } return arr ; } };
相关文章推荐
- pair的用法
- 欢迎使用CSDN-markdown编辑器
- 学会这10招让你成为杰出的Java程序员
- 【leetcode】154. Find Minimum in Rotated Sorted Array II
- 求幂集的算法
- 笔试题43. LeetCode OJ (30)
- JavaScript的属性访问
- HDU 3678 2-SAT
- 幽灵按钮的实现
- Struts之OGNL
- Learning How to Learn
- TCP_Wrappers应用级防火墙介绍与配置
- 安装和使用IIS的URL重写工具
- 常用vim命令合集
- 在不看任何数学公式的情况下理解傅里叶分析
- 利用PHP绘图函数实现简单验证码功能
- ZkClient
- 20145337实验四Android开发基础
- 网络安全---linux下的snort系统的安装和规则测试(一)
- 二叉树链式存储的C实现