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

    第五次作业对我个人来说是很难的,因为之前没怎么接触过这方面的内容,有幸能跟宗毅组成一队,我也仔细看了他的Python代码,因为对于Python也是第一次接触,所以我感觉在有限的时间里学会并且灵活运用还 ...

  2. centos5 vim升级到7.4

    vim在centos中的版本为7.0,导致很多插件都无法使用,所以想到升级一下. wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2 tar jvz ...

  3. delphi回调函数

    文章来源: http://anony3721.blog.163.com/blog/static/5119742010866050589/ 一.主单元 unit UnMain; interface us ...

  4. Java IO (3) - Reader

    Java IO (3) - Reader 前言 JavaIO一共包括两种,一种是stream,一种是reader/writer,每种又包括in/out,所以一共是四种包.Java 流在处理上分为字符流 ...

  5. C#中Internal class与静态类说明

    C#中的internal访问修饰符表示 访问仅限于当前程序集 但是注意,internal修饰符修饰的类中,可以有public的成员变量和成员方法等 Static 关键字作为修饰符可以用于类.方法和成员 ...

  6. 从Jetty、Tomcat和Mina中提炼NIO构架网络服务器的经典模式(一)

    本文转载自 http://blog.csdn.net/cutesource/article/details/6192016 如何正确使用NIO来构架网络服务器一直是最近思考的一个问题,于是乎分析了一下 ...

  7. ibatis 搭建总结

    一.搭建ibatis环境 1.导入ibatis的jar包,已及数据库驱动jar包ibatis-2.3.0.677.jar ibatis-dao-2.jar ibatis-sqlmap-2.jar ib ...

  8. mysql case when 条件过滤

    [1].[代码] 使用CASE WHEN进行字符串替换处理 跳至 [1] [2] [3] [4] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  9. VS2012开发ActiveX插件 尝试1

    今天闲来无聊研究了下 ActiveX插件开发,以前一直以为很牛逼,然后发现还是比较简单的东西.. 首先: 在开始前 准备好 VS12开发工具,cabarc.exe 工具(注:这是 用来 将文件打包成c ...

  10. Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改

    A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/pro ...