343 Integer Break 整数拆分
给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。
例如,给定 n = 2,返回1(2 = 1 + 1);给定 n = 10,返回36(10 = 3 + 3 + 4)。
注意:你可以假设 n 不小于2且不大于58。
详见:https://leetcode.com/problems/integer-break/description/
C++:
class Solution {
public:
int integerBreak(int n) {
if(n==2||n==3)
{
return n-1;
}
int res=1;
while(n>4)
{
res*=3;
n-=3;
}
return res*n;
}
};
参考:https://www.cnblogs.com/grandyang/p/5411919.html
343 Integer Break 整数拆分的更多相关文章
- [LeetCode] 343. Integer Break 整数拆分
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- [LeetCode] Integer Break 整数拆分
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 【LeetCode】343. Integer Break 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学解法 动态规划 日期 题目地址:https:// ...
- 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 ...
- #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 ...
- leetcode 343. Integer Break(dp或数学推导)
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- Leetcode 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 343. Integer Break -- Avota
问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...
- (dp)343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
随机推荐
- redis—持久化
Redis持久化 概述 Redis的强大性能很大程度上都是因为所有数据都是存储在内存中的,然而当Redis重启后,所有存储在内存中的数据将会丢失,在很多情况下是无法容忍这样的事情的.所以,我们需要将内 ...
- Hello Shiro
[HelloWorld Shiro] 1.搭建开发环境-加入jar包 2.步骤(前提:已下载好Shiro资源包): ①找到shiro-root-1.2.3-source-release包, ②按Apa ...
- 【08】AngularJS XMLHttpRequest
AngularJS XMLHttpRequest $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据. 读取 JSON 文件 以下是存储在web服务器上的 JSON 文件: ...
- 【Codeforces 494A】Treasure
[链接] 我是链接,点我呀:) [题意] 让你把"#"用至少一个右括号代替 使得整个括号序列合法 [题解] 首先我们不要考虑井号 考虑最简单的括号序列 并且把左括号看成1,右括号看 ...
- hdu 2844 多重背包二进制优化
//http://www.cnblogs.com/devil-91/archive/2012/05/16/2502710.html #include<stdio.h> #define N ...
- Codeforces Round #391(div 1+2)
A =w= B QuQ C 题意:有n个体育场,每个体育场有一些小精灵,一共m种小精灵(n<=1e5,m<=1e6),可以将数字全为i的精灵进化成j(可以互相进化也可以选择不进化),问有多 ...
- Java的23种设计模式(转)
设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 毫无疑问,设计模式于 ...
- A new Graph Game
点击打开链接 题意:给你一张N个节点的无向图.然后给出M条边,给出第 I 条边到第J条边的距离.然后问你是否存在子环,假设存在,则输出最成环的最短距离和 解析:构图:选定源点及汇点,然后将源点至个点流 ...
- 将一个对象相同的属性(不区分大小写)赋值给一个新对象 DataTable的一个简单的扩展
将一个对象相同的属性(不区分大小写)赋值给一个新对象 1 public static T Mapper<S, T>(S source) 2 { 3 T t = Activator.Cr ...
- BAT 前端开发面经 —— 吐血总结 前端相关片段整理——持续更新 前端基础精简总结 Web Storage You don't know js
BAT 前端开发面经 —— 吐血总结 目录 1. Tencent 2. 阿里 3. 百度 更好阅读,请移步这里 聊之前 最近暑期实习招聘已经开始,个人目前参加了阿里的内推及腾讯和百度的实习生招聘, ...