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 ...
随机推荐
- 疫情控制(codevs 1218)
题目描述 Description H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都, 也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为 ...
- [bzoj1293][SCOI2009]生日礼物(单调队列)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1293 分析: 问题的关键就是选择每种颜色的哪一个好.可以先把每种颜色的第一个一起,更新 ...
- 走进windows编程的世界-----画图相关
Windows画图 1 图形绘制 1.1 图形绘制的方式 获取到画图句柄-设备描写叙述表(DC),使用对应的画图的API,在设备上绘制图形. 1.2 颜色 ...
- Windows编程中char*转LPCWSTR解决的方法总结
Windows编程中常常涉及到的一个问题是字符串之间的转换,开发过程总是遇到编译器提示无法格式转换的问题.于是自己总结了几种解决的方法. 1.通过T2W转换宏 char* szStr = " ...
- 【Cocos2dx游戏开发】CCNotificationCenter传递消息和数据
在开发游戏的时候我们经常需要在层与层之间.场景与场景之间传递数据和消息,Cocos2dx框架应用观察者模式为我们封装了一个CCNotificationCenter类,也叫消息通知中心,它也是一个单例类 ...
- scikit-learn:4.7. Pairwise metrics, Affinities and Kernels
參考:http://scikit-learn.org/stable/modules/metrics.html The sklearn.metrics.pairwise submodule implem ...
- Android获取全部存储卡挂载路径
近期因项目需求.须要在存储卡查找文件,经測试发现部分手机挂载路径查找不到,这里分享一个有效的方法. /** * 获取全部存储卡挂载路径 * @return */ public static List& ...
- shell 切割文件
[root@hadoop2 xiaole_chk_url]# cat looh.index.splitfile.sh loop_c=0loop_step=10001loop_tag=0str_head ...
- codeforce 1073E. Segment Sum
看到这个就是数位DP了,然而细节极多,对于i=1状态直接判了,还有最后一位直接算了 设f[i][zt][0/1]表示枚举到第i位,用了那些数字,是否有前导0(前导0不计入数字,否则就不知道后面有没有0 ...
- js如何获取某id的子标签
思路:根据id获取父对象,然后使用childNodes获取所有子对象数组,关键代码: document.getElementById(div_id).childNodes; // 子对象数组 实例 ...