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. [COCOS2D-X]AssetsManager

    转自:http://blog.csdn.net/xpwang168/article/details/8900764 资源更新方式分析 I zip整包更新 优点:省流量,速度快 缺点:有重复资源,需要打 ...

  2. 最大二位子数组和问题(homework-02)

    前面已经谈过最大一维子数组和问题,这里面扩展到二维. 一. 常规情况 一个矩形的数组,找到一个矩形的子数组有最大的元素和,求这个和. 1. 从朴素算法入手,枚举矩形数组的4个顶点,以此计算其数组和.同 ...

  3. CentOS 搭建LNMP服务器和LAMP服务器

    CentOS 搭建LNMP服务器 方法一:yum安装 1.更新YUM源 wget http://www.atomicorp.com/installers/atomic   #下载atomic自动更新Y ...

  4. php把时间格式化

    如题,把如 2013-6-12 12:00 格式化为 2013-6--12 可以先将时间转换下,然后重新将时间格式化显示: echo date("Y-m-d", strtotime ...

  5. [转]JSON.stringify 语法实例讲解

    原文地址:http://www.jb51.net/article/29893.htm 作用:这个函数的作用主要是为了系列化对象的. 可能有些人对系列化这个词过敏,我的理解很简单.就是说把原来是对象的类 ...

  6. Lua学习笔记(四):表和数组

    表 在Lua中,表(table)是十分重要的一种数据结构,实际上Lua对于复杂数据类型也仅提供了表给我们,我们通过表可以实现我们需要的大部分重要的数据结构,比如数组. table类型实现了关联数组,关 ...

  7. Python3批量爬取网页图片

    所谓爬取其实就是获取链接的内容保存到本地.所以爬之前需要先知道要爬的链接是什么. 要爬取的页面是这个:http://findicons.com/pack/2787/beautiful_flat_ico ...

  8. 安装centreon

     Centreon + nagios + ndoutils 安装 2013-09-25 19:42:44 标签:centreon 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者 ...

  9. C# 常用日期类型转换帮助类

    本文转载:http://www.cnblogs.com/iamlilinfeng/p/3378659.html 最近工作比较忙,与此同时自己也在业余时间开发一个电子商务网站.虽然每天都很累,但感觉过的 ...

  10. EasyUI基础入门之Parser(解析器)

    前言 JQuery EasyUI提供的组件包含功能强大的DataGrid,TreeGrid.面板.下拉组合等.用户能够组合使用这些组件,也能够单独使用当中一个.(使用的形式是以插件的方式提供的) Ea ...