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.

Hint:

There is a simple O(n) solution to this problem.
You may check the breaking results of n ranging from 7 to 10 to discover the regularities.

 /*************************************************************************
> File Name: LeetCode343.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: Tue 10 May 2016 04:17:35 PM CST
************************************************************************/ /************************************************************************* 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. Hint: There is a simple O(n) solution to this problem.
You may check the breaking results of n ranging from 7 to 10 to discover the regularities. ************************************************************************/ #include<stdio.h> int integerBreak( int n )
{
if( n <= )
{
return ;
}
if( n == )
{
return ;
}
int ret = ;
while( n > )
{
ret *= ;
n -= ;
}
return ret*n;
} int main()
{
int n = ;
int ret = integerBreak(n);
printf("%d\n",ret); return ;
}

LeetCode 343的更多相关文章

  1. LeetCode 343.整数拆分 - JavaScript

    题目描述:给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 题目分析 题目中"n 至少可以拆分为两个正整数的和",这个条件说 ...

  2. [LeetCode] 343. Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  3. LeetCode 343. 整数拆分(Integer Break) 25

    343. 整数拆分 343. Integer Break 题目描述 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 每日一算法2019/5/2 ...

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

  5. leetcode 343. Integer Break(dp或数学推导)

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

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

  7. Java实现 LeetCode 343 整数拆分(动态规划入门经典)

    343. 整数拆分 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 示例 1: 输入: 2 输出: 1 解释: 2 = 1 + 1, 1 × ...

  8. Leetcode 343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  9. leetcode 343 整数拆分

    1.这个题拿到之后没有什么思路,此时就应该考虑暴力法.然而每次不知道要拆成几份,没办法用循环,所以想到用递归. 如图所示进行递归,显然有很多重复的计算,所以用自底向上的动态规划. 2.还有一个问题就是 ...

随机推荐

  1. java封装对象转json字符串

    /** * Copyright (c) 2011-2015, James Zhan 詹波 (jfinal@126.com). * * Licensed under the Apache License ...

  2. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

  3. HDU 4052 Adding New Machine (线段树+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4052 初始给你w*h的矩阵,给你n个矩形(互不相交),按这些矩形尺寸把初始的矩形扣掉,形成一个新的'矩 ...

  4. 开源 免费 java CMS - FreeCMS1.5-信息管理

    下载地址:http://code.google.com/p/freecms/ 信息管理 1. 快速添加 从左侧管理菜单点击快速添加进入. 输入相关属性后添加“保存”按钮即可. 从FreeCMS 1.4 ...

  5. 一款多浏览器兼容的javascript多级下拉菜单

    这个多级下拉菜单的脚本大小不到2K,带有动画效果,可以方便地支持多个实例,并且能良好兼容WordPress系统wp_list_cats和wp_list_pages生成的多级列表.要初始化一个菜单,只需 ...

  6. 使用SVG Path绘图

    最近一个项目,需要做个Web版本的设计器,用来进行工厂流水线布局的设计. 项目中采用了SVG.JS来做,但是以前流水线是采用单纯的画线的方式实现.客户提出希望用不同的底纹表示不同的流水线,经过一番调查 ...

  7. python常用字符串操作

    #!/usr/bin/env python name='cunzhang' print(name.capitalize())#首字母大写 print(name.count('n'))#统计字符有几个 ...

  8. servlet--页面自刷新

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...

  9. mysql5.5主从配置

    mysql主从同步# 一:mysql数据库的主从 mysql数据库5.5之后的版本和5.5以前的版本数据库主从存在差异,这里是针对数据库5.5之后的配置. 1.主库编辑my.cnf(linux的my. ...

  10. Andoird Studio 错误: 非法字符: '\ufeff' 解决方案。

    从网上下载一个安卓UI模板,导入到AndroidStudio的时候提示MainActivity非法字符: '\ufeff' 解决方案,细细一想编译器没报错,但编译出错,应该是隐蔽字符BOM的问题,于是 ...